Laravel 7 create model,and migration in single artisan command

Laravel 7 create model,and migration in single artisan command

php artisan make:controller TodoController --resource --model=Todo


      migrate          Run the database migrations
      migrate:fresh    Drop all tables and re-run all migrations  
      migrate:install  Create the migration repository
      migrate:refresh  Reset and re-run all migrations
      migrate:reset    Rollback all database migrations
      migrate:rollback Rollback the last database migration       
      migrate:status   Show the status of each migration
f 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
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.
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.
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
And that’s it. Laravel will actually ask you if you want to generate the model:
Here is the command output showing the differences:
$ php artisan migrate:refresh

Rolling back: 2014_10_12_100000_create_password_resets_table
Rolled back:  2014_10_12_100000_create_password_resets_table
Rolling back: 2014_10_12_000000_create_users_table
Rolled back:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table
Now, with the new fresh command:
$ php artisan migrate:fresh

Dropped all tables successfully.
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table
That’s it, quick tip to perform quick operation!

Reactions

Post a Comment

0 Comments

close