In this short snippet, you will learn how to create model, controller and migration in a single artisan command in the laravel.
Lets get started!
php artisan make:model Article -mc
`As you can see in the above command, the only way to create all three model, controller and migration are by creating the model first with some additional flags for the migration and controller.
Where m stands for migration and c for the controller.
Table of Contents
Flags which available For Make Model in laravel:
The following flags are available which we can use with make model commands:
-c, –controller For crating new controller for the model
-f, –factory For creating new factory for the model
–force For creating class even if the model exists
-m, –migration For creating migration for the model
-s, –seed For creating seeder file for the model
-p, –pivot Which indicates that the generated model is an intermediate pivot table
-r, –resource For Indicating if the generated controller should be a resource controller
–all Which will include all the above flags.
How to create a model with all flags?
The command below will generate a model with all the flags.
php artisan make:model Article --all
How to create a model with a seeder?
The command below will generate a model with all the flags.
php artisan make:model Article -s
Conclusion:
Hope you have learned in the above article on creating model, controller and migration in laravel.
See you at the next one 🙂
Write a Reply or Comment