Laravel comes with a handy artisan command to create a model for your application. In this post, we take a look at various ways to create a model class using the artisan command.
To create only a model class, run the artisan command below:
php artisan make:model Photo
You will get a model class file at app/Models/Photo.php
.
To create only a pivot model class, run the artisan command below:
php artisan make:model Photo --pivot
You will get a model class file at app/Models/Photo.php
.
To create only a model class with a migration, run the artisan command below:
php artisan make:model Photo -m
You will get a model class file at app/Models/Photo.php
along with a migration file in database/migrations/
folder.
To create only a model class with a factory, run the artisan command below:
php artisan make:model Photo -f
You will get a model class file at app/Models/Photo.php
along with a factory class at database/factories/PhotoFactory.php
.
To create only a model class with a seeder, run the artisan command below:
php artisan make:model Photo -s
You will get a model class file at app/Models/Photo.php
along with a seeder class at database/seeders/PhotoSeeder.php
.
To create only a model class with a controller, run the artisan command below:
php artisan make:model Photo -c
You will get a model class file at app/Models/Photo.php
along with a controller class at app/Http/Controllers/PhotoController.php
.
To create only a model class with a policy, run the artisan command below:
php artisan make:model Photo --policy
You will get a model class file at app/Models/Photo.php
along with a policy class at app/Policies/PhotoPolicy.php
.
You can certainly combine multiple options when creating a model class, for example, if you wish to create a model with a seeder and a migration, you can do so by running the command below:
php artisan make:model Photo -s -m