Reputation: 4813
I can create a model and resource controller (binded to model) with the following command
php artisan make:controller TodoController --resource --model=Todo
I want to also create a migration with the above command, is it possible?
Upvotes: 276
Views: 586814
Reputation: 399
php artisan make:model Author -cfmsr
-c, --controller Create a new controller for the model
-f, --factory Create a new factory for the model
-m, --migration Create a new migration file for the model
-s, --seed Create a new seeder file for the model
-r, --resource Indicates if the generated controller should be a resource controller
Upvotes: 9
Reputation: 331
If you are using Laravel as an only API add --api
option:
php artisan make:model Post -a --api
Upvotes: 6
Reputation: 1754
Updated
Laravel 6 or Later
Through the model
To Generate a migration, seeder, factory and resource controller for the model
php artisan make:model Todo -a
Or
php artisan make:model Todo -all
Other Options
-c, --controller Create a new controller for the model
-f, --factory Create a new factory for the model
--force Create the class even if the model already exists
-m, --migration Create a new migration file for the model
-s, --seed Create a new seeder file for the model
-p, --pivot Indicates if the generated model should be a custom intermediate table model
-r, --resource Indicates if the generated controller should be a resource controller
For More Help
php artisan make:model Todo -help
Hope Newbies will get help.
Upvotes: 68
Reputation: 31
How I was doing it until now:
php artisan make:model Customer
php artisan make:controller CustomersController --resource
Apparently, there’s a quicker way:
php artisan make:controller CustomersController --model=Customer
Upvotes: 1
Reputation: 79
You don't need to add --resource flag just type the following and laravel will create the whole desired resources
php artisan make:controller TodoController --model=todo
Upvotes: 3
Reputation: 10111
You can make model + migration + controller, all in one line, using this command:
php artisan make:model --migration --controller test
Short version: php artisan make:model -mc test
Output :-
Model created successfully.
Created Migration:2018_03_10_002331_create_tests_table
Controller created successfully.
If you need to perform all CRUD operations in the controller then use this command:
php artisan make:model --migration --controller test --resource
Short version: php artisan make:model -mc test --resource
Upvotes: 34
Reputation: 983
We can use php artisan make:model Todo -a
to create model, migration, resource controller and factory
Upvotes: 4
Reputation: 13244
You can do it if you start from the model
php artisan make:model Todo -mcr
if you run php artisan make:model --help
you can see all the available options
-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
Update
As mentioned in the comments by @arun in newer versions of laravel > 5.6 it is possible to run following command:
php artisan make:model Todo -a
-a, --all Generate a migration, factory, and resource controller for the model
Upvotes: 660