Posts Learn Components Snippets Categories Tags Tools new About
/

How to Create Model, Migration and Controller Using Single Artisan Command in Laravel

Get to know how to create a model, migration, and controller using a single artisan command in the Laravel application

Created on Oct 28, 2021

44 views

In this short snippet, you will learn how to create a Model, Migration, and Controller using single artisan command. The way to achieve this is by passing a flag to the "make:model" command.
php artisan make:model -mc Post
The command above will create the model as well as the "migration (m)" and "controller (c)" for the "Post" resource.

Available Flags For Make Model in laravel


The available commands to make the model in Laravel is available below.
-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
If you do want to create all then do specify the "--all" flag when running the model.
php artisan make:model Post -all
To get the details of what flag you can pass in, you can run the command with "-help" flag like below.
php artisan make:model Todo -help

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

)