make:model command generates a new model class in the App/Models directory with optional migration.
Syntax
string
required
The name of the model class (use PascalCase, singular)
flag
Automatically create a migration file for the model
Basic Usage
Create a new model:With Migration
Create a model and migration together:Using the
--migration flag automatically generates both the model and a matching migration file, saving you time.Generated Model
The command creates a model that extends Lyger’s baseModel class:
App/Models/User.php
Table Name Convention
The table name is automatically derived from the model name using snake_case pluralization:rawr (line 246)
Model Properties
$table
Specifies the database table for the model:You can override this if your table name doesn’t follow the convention.
$fillable
Defines which attributes can be mass-assigned:Naming Conventions
Model names should:
- Use PascalCase (e.g.,
User,Product,BlogPost) - Be singular (the table will be automatically pluralized)
- Represent a single entity or record
Valid Names
Invalid Names
Error Handling
Missing Name
Duplicate Model
Complete Example
Create a model with all common properties:Common Patterns
User Model
App/Models/User.php
Pivot Model
For many-to-many relationships:App/Models/OrderProduct.php
Polymorphic Model
For polymorphic relationships:App/Models/Comment.php
Using Models
After creating a model, you can use it to interact with the database:Create Records
Query Records
Update Records
Delete Records
Source Code
The model generation logic:rawr (lines 227-270)
Workflow Example
Next Steps
Make Migration
Create database migrations
Eloquent ORM
Learn about the ORM features
Relationships
Define model relationships
Query Builder
Build complex queries