The make:model command generates a new model class in the App/Models directory with optional migration.
Syntax
php rawr make:model < Nam e > [--migration]
The name of the model class (use PascalCase, singular)
Automatically create a migration file for the model
Basic Usage
Create a new model:
Output:
Model created: App/Models/User.php
With Migration
Create a model and migration together:
php rawr make:model Product --migration
Output:
Model created: App/Models/Product.php
Migration created: database/migrations/2026_03_08_143022_create_products_table.php
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 base Model class:
<? php
declare ( strict_types = 1 );
namespace App\Models ;
use Lyger\Database\ Model as BaseModel ;
class User extends BaseModel
{
protected string $table = 'users' ;
protected array $fillable = [];
}
Table Name Convention
The table name is automatically derived from the model name using snake_case pluralization:
Model Name Generated Table Name UserusersProductproductsBlogPostblog_postsOrderItemorder_items
$tableName = strtolower ( preg_replace ( '/(?<! ^ )[A-Z]/' , '_' , $name )) . 's' ;
Model Properties
$table
Specifies the database table for the model:
protected string $table = 'users' ;
You can override this if your table name doesn’t follow the convention.
$fillable
Defines which attributes can be mass-assigned:
protected array $fillable = [ 'name' , 'email' , 'password' ];
This protects against mass-assignment vulnerabilities:
// Safe - only fillable attributes are assigned
$user = new User ([ 'name' => 'John' , 'email' => 'john@example.com' ]);
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
php rawr make:model User
php rawr make:model Product
php rawr make:model BlogPost
php rawr make:model OrderItem
Invalid Names
php rawr make:model Users # Should be singular (User)
php rawr make:model user # Should use PascalCase (User)
php rawr make:model user-model # No hyphens allowed
Error Handling
Missing Name
Output:
Error: Model name required
Duplicate Model
php rawr make:model User
# Run again
php rawr make:model User
Output:
Error: Model User already exists
Complete Example
Create a model with all common properties:
Command
App/Models/Product.php
Generated Migration
php rawr make:model Product --migration
Common Patterns
User Model
<? php
declare ( strict_types = 1 );
namespace App\Models ;
use Lyger\Database\ Model as BaseModel ;
class User extends BaseModel
{
protected string $table = 'users' ;
protected array $fillable = [
'name' ,
'email' ,
'password'
];
protected array $hidden = [
'password' ,
'remember_token'
];
// Hash password before saving
public function setPasswordAttribute ( string $value ) : void
{
$this -> attributes [ 'password' ] = password_hash ( $value , PASSWORD_DEFAULT );
}
// Relationships
public function posts ()
{
return $this -> hasMany ( Post :: class );
}
}
Pivot Model
For many-to-many relationships:
php rawr make:model OrderProduct
App/Models/OrderProduct.php
<? php
declare ( strict_types = 1 );
namespace App\Models ;
use Lyger\Database\ Model as BaseModel ;
class OrderProduct extends BaseModel
{
protected string $table = 'order_product' ;
protected array $fillable = [
'order_id' ,
'product_id' ,
'quantity' ,
'price'
];
public $timestamps = false ;
}
Polymorphic Model
For polymorphic relationships:
php rawr make:model Comment
<? php
declare ( strict_types = 1 );
namespace App\Models ;
use Lyger\Database\ Model as BaseModel ;
class Comment extends BaseModel
{
protected string $table = 'comments' ;
protected array $fillable = [
'content' ,
'commentable_id' ,
'commentable_type'
];
public function commentable ()
{
return $this -> morphTo ();
}
}
Using Models
After creating a model, you can use it to interact with the database:
Create Records
use App\Models\ Product ;
// Create a new product
$product = new Product ();
$product -> name = 'Laptop' ;
$product -> price = 999.99 ;
$product -> save ();
// Or use mass assignment
$product = Product :: create ([
'name' => 'Laptop' ,
'price' => 999.99
]);
Query Records
// Find by ID
$product = Product :: find ( 1 );
// Get all products
$products = Product :: all ();
// Query with conditions
$expensive = Product :: where ( 'price' , '>' , 500 ) -> get ();
// Use scopes
$inStock = Product :: inStock () -> get ();
Update Records
$product = Product :: find ( 1 );
$product -> price = 899.99 ;
$product -> save ();
// Or update directly
Product :: where ( 'id' , 1 ) -> update ([ 'price' => 899.99 ]);
Delete Records
$product = Product :: find ( 1 );
$product -> delete ();
// Or delete directly
Product :: where ( 'price' , '<' , 10 ) -> delete ();
Source Code
The model generation logic:
function makeModel ( string $basePath , ? string $name , bool $withMigration = false ) : void
{
if ( $name === null ) {
echo "Error: Model name required \n " ;
exit ( 1 );
}
$modelsPath = $basePath . '/App/Models' ;
if ( ! is_dir ( $modelsPath )) {
mkdir ( $modelsPath , 0755 , true );
}
$modelPath = $modelsPath . '/' . $name . '.php' ;
if ( file_exists ( $modelPath )) {
echo "Error: Model { $name } already exists \n " ;
exit ( 1 );
}
$tableName = strtolower ( preg_replace ( '/(?<! ^ )[A-Z]/' , '_' , $name )) . 's' ;
$content = <<< PHP
<?php
declare(strict_types=1);
namespace App\Models;
use Lyger\Database\Model as BaseModel;
class { $name } extends BaseModel
{
protected string \$ table = '{ $tableName }';
protected array \$ fillable = [];
}
PHP ;
file_put_contents ( $modelPath , $content );
echo "Model created: App/Models/{ $name }.php \n " ;
if ( $withMigration ) {
makeMigration ( $basePath , 'create_' . $tableName . '_table' );
}
}
Workflow Example
Step 1: Create Model
Step 2: Define Fillable
Step 3: Define Migration
Step 4: Run Migration
Step 5: Use Model
php rawr make:model Order --migration
Next Steps
Make Migration Create database migrations
Eloquent ORM Learn about the ORM features
Relationships Define model relationships
Query Builder Build complex queries