[laravel] Laravel 5.4 create model, controller and migration in single artisan command

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?

This question is related to laravel laravel-5.4 laravel-artisan

The answer is


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


Updated

Laravel 6 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 inte rmediate table model

-r, --resource Indicates if the generated controller should be a resour ce controller

For More Help

php artisan make:model Todo -help

Hope Newbies will get help.


Just Try this command on your terminal

php artisan make:model Todo -mcr

Below the output and your Model, Controller with Resource and Migration file will create...

Model created successfully.
Created Migration: 2019_12_25_105305_create_todos_table
Controller created successfully.

You can do it with the following command:

php artisan make:model post -mcr

Brief :

-m, to create migration

-c to create controller

-r to specify the controller has resource


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


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.


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

To make all 3: Model, Controller & Migration Schema of table

write in your console: php artisan make:model NameOfYourModel -mcr


Instead of using long command like

php artisan make:model <Model Name> --migration --controller --resource

for make migration, model and controller, you may use even shorter as -mcr.

php artisan make:model <Model Name> -mcr

For more MOST USEFUL LARAVEL ARTISAN MAKE COMMANDS LISTS


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

We can use php artisan make:model Todo -a to create model, migration, resource controller and factory


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


You can use -m -c -r to make migration, model and controller.

php artisan make:model Post -m -c -r

Examples related to laravel

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration Target class controller does not exist - Laravel 8 Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required How can I run specific migration in laravel Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

Examples related to laravel-5.4

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1 Laravel 5.4 Specific Table Migration Including a css file in a blade template? How to logout and redirect to login page using Laravel 5.4? PHP7 : install ext-dom issue Laravel 5.4 create model, controller and migration in single artisan command laravel 5.4 upload image How to validate array in Laravel? Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Examples related to laravel-artisan

No Application Encryption Key Has Been Specified Laravel 5.4 create model, controller and migration in single artisan command SQLSTATE[HY000] [2002] Connection refused within Laravel homestead ReflectionException: Class ClassName does not exist - Laravel Artisan, creating tables in database Laravel 5 Clear Views Cache Laravel 5 How to switch from Production mode Could not open input file: artisan Laravel 5 - artisan seed [ReflectionException] Class SongsTableSeeder does not exist What are the Differences Between "php artisan dump-autoload" and "composer dump-autoload"?