Laravel Artisan Generator Command: The make:model Command

December 7, 2016 —John Koster

The make:model command is used to generate new Eloquent model classes. It requires a name to be supplied; this name will become the name of the generated class and created file. A migration file can also be generated for the model by setting the --migration flag (or by using the -m shortcut). Newly created classes are stored in the app/ directory.

This command will not overwrite any existing model classes that have the same name. An error stating Model already exists! will be displayed instead.

The following examples demonstrate how to call the make:model command.

The following would create a new model class for Drink:

1# Create a new Drink model.
2php artisan make:model Drink

the resulting class would look similar to the following:

1<?php
2 
3namespace App;
4 
5use Illuminate\Database\Eloquent\Model;
6 
7class Drink extends Model
8{
9 //
10}

The following examples would also generate a migration for the model:

1# Create a new Drink model and migration.
2php artisan make:model Drink -m

The previous example is equivalent to the following series of commands:

1php artisan make:model Drink
2php artisan make:migration create_drinks_table --create=drinks

The make:model command is also capable of generated namespaced classes. Accomplish this by separating namespace sections using the \ when supplying the model name. A nested directory will be created and the correct namespace will be set on the generated class.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.