问题
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?
回答1:
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
回答2:
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
回答3:
You can do it with the following command:
php artisan make:model post -mc
回答4:
php artisan make:model PurchaseRequest -crm
The Result is
Model created successfully.
Created Migration: 2018_11_11_011541_create_purchase_requests_table
Controller created successfully.
Just use -crm instead of -mcr
回答5:
Laravel 5.4 You can use
php artisan make:model --migration --controller --resource Test
This will create 1) Model 2) controller with default resource function 3) Migration file
And Got Answer
Model created successfully.
Created Migration: 2018_04_30_055346_create_tests_table
Controller created successfully.
回答6:
We can use php artisan make:model Todo -a
to create model, migration, resource controller and factory
回答7:
To make mode, controllers with resources, You can type CMD as follows :
php artisan make:model Todo -mcr
or you can check by typing
php artisan help make:model
where you can get all the ideas
回答8:
You can use -m -c -r to make migration, model and controller.
php artisan make:model Post -m -c -r
回答9:
To make all 3: Model, Controller & Migration Schema of table
write in your console: php artisan make:model NameOfYourModel -mcr
回答10:
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
回答11:
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
来源:https://stackoverflow.com/questions/43187735/laravel-5-4-create-model-controller-and-migration-in-single-artisan-command