Skip to content

Laravel create model, controller and migration in single artisan command

Written by

sysadmin

For Laravel 5.6 and older:

php artisan make:model Todo -mcr

-m, –migration Create a new migration file for the model.
-c, –controller Create a new controller for the model.
-r, –resource Indicates if the generated controller should be a resource controller

and for Laravel 5.7 and newer:

php artisan make:model Todo -a

-a, –all Generate a migration, factory, and resource controller for the model

or you can make model + migration + controller, all in one line, using this command:

php artisan make:model --migration --controller Todo

Output:

Model created successfully.

Created Migration: 2020_04_11_202633_create_todos_table

Controller created successfully.

and if you need to perform all CRUD operations in the controller then use this command:

php artisan make:model -mc Todo --resource

Previous article

Laravel specific table migration in single artisan command

Next article

Laravel handle incoming emails in your application