Create Laravel Model, Migration, Controller, and Resource in One Command

Yes, you can create a model, migration, controller, and resource (views) with one command in the laravel. You just have to add an additional flag while creating a new model with the PHP artisan command. So let’s see how we can do this.

We all know this PHP artisan command for creating a model.

php artisan make:model user

Now we will add an additional flag to tell the artisan command to also create a migration, controller, and resource along with the model. See the command below.

php artisan make:model user -mcr

The above command will generate the files for migration, controller, and resource (view), and of course model files. This is short abbreviation command for creating all together in one command.

References:
-m => for create the migration
-c => for create the controller
-r => for create the resource

Hope this trick will help you to create a model, migration, resource, and controller with one laravel command. So use this trick to save your time. You can read more about artisan command here.

Being Tricky 😉

About the Author: Aman Mehra

Hey! I'm Aman Mehra and I'm a full-stack developer and have 5+ years of experience. I love coding and help to people with this blog.

Leave a Reply

Your email address will not be published. Required fields are marked *