Laravel Model Generator
Generate a complete Laravel Eloquent Model class with fillable attributes, casts, relationships, and more.
- Home
- > Web Dev > Laravel Tools >
- Model Generator
Singular CamelCase, e.g. Post, BlogPost, UserProfile
Auto-filled from model name. Uses Laravel convention: snake_case + plural.
Comma-separated column names. Leave empty for $guarded.
Comma-separated. Only used when fillable is empty.
Add attribute casts (e.g. is_admin → boolean).
Foreign key and local key are auto-resolved by Laravel convention if left blank.
Comma-separated full trait class names.
Generated Model
How to Use the Laravel Model Generator
This tool helps you quickly create a Laravel Eloquent model class with full configuration. Follow these steps:
- Enter the model name — Type a singular CamelCase name like
PostorUserProfile. The table name auto-fills. - Configure options — Expand each section to set fillable attributes, casts, relationships, traits, and more.
- Add casts — Click Add Cast to map attributes to types like boolean, array, json, or datetime.
- Add relationships — Click Add Relationship to define
belongsTo,hasMany, and more. - Generate — Click Generate Model to create the PHP class.
- Copy or Download — Click Copy to copy the PHP code, or Download to save as
Post.php.
Tip
After generating, place the file in app/Models/. Then run php artisan make:model Post or paste the generated code directly.
Frequently Asked Questions
What naming convention should I use for my model?
Use singular CamelCase: Post, BlogPost, UserProfile. Laravel automatically maps Post to the posts table. You can override this with the $table property.
What is the difference between $fillable and $guarded?
$fillable is a whitelist of attributes that can be mass-assigned. $guarded is a blacklist. Use one or the other — if $fillable is set, $guarded is ignored.
What are attribute casts?
Casts tell Eloquent how to convert attribute values when you access them. For example, a boolean cast converts is_admin from 0/1 to true/false, while array/json automatically serialize/deserialize JSON columns.
Should I include HasFactory?
Yes, unless you never use model factories. HasFactory is included by Laravel in every generated model and is required for testing with factories.
Can I customize the namespace?
Yes. The default namespace is App\Models (Laravel 8+). If you use a different structure like App\Domain\Posts\Models, update the Namespace field.