Automatically generate Eloquent models from database tables with professional PHPDoc, relationships, and multi-database support
amranibrahem/laravel-model-generator is a Laravel package for automatically generate eloquent models from database tables with professional phpdoc, relationships, and multi-database support.
It currently has 0 GitHub stars and 22 downloads on Packagist (latest version v2.1.2).
Install it with composer require amranibrahem/laravel-model-generator.
Discover more Laravel packages by amranibrahem
or browse all Laravel packages to compare alternatives.
Last updated
π Generate Eloquent Models Automatically from Database Tables
A powerful Laravel package that automatically generates Eloquent models from your database tables with professional PHPDoc, relationships, and casting.
You can install the package via Composer:
composer require amranibrahem/laravel-model-generator
1- Generate All Models
php artisan models:generate
2- Generate Specific Tables
php artisan models:generate --tables=users,posts,comments
3- Generate with Relationships
php artisan models:generate --relationships
4- Update Existing Models
php artisan models:generate --force --relationships
5- Custom Path and Namespace
php artisan models:generate --path=app/Domain --namespace=App\\Domain
6- Combine Options
php artisan models:generate --tables=users,posts --relationships --force --path=app/Models
Generated Model Example
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* @property int $id
* @property string $name
* @property string $email
* @property string $password
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @property-read \App\Models\Comment[] $comments
* @property-read \App\Models\Post[] $posts
*/
class User extends Model
{
use HasFactory;
protected $table = 'users';
protected $fillable = [
'name',
'email',
'password'
];
protected $casts = [
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
/**
* Get all the Comment for the User.
*/
public function comments()
{
return $this->hasMany(Comment::class, 'user_id', 'id');
}
/**
* Get all the Post for the User.
*/
public function posts()
{
return $this->hasMany(Post::class, 'user_id', 'id');
}
}
Many-to-Many Relationship Example
/**
* @property \App\Models\Tag[] $tags
*/
class Post extends Model
{
public function tags()
{
return $this->belongsToMany(Tag::class, 'post_tag', 'post_id', 'tag_id');
}
}
| Option | Description | Default |
|--------|-------------|---------|
| --tables | Specific tables to generate (comma separated) | All tables |
| --path | Models directory path | app/Models |
| --namespace | Models namespace | App\Models |
| --relationships | Auto generate relationships | false |
| --force | Update existing models with missing properties | false |
π Starting Model Generation...
β
Generated model: User
β
Updated model with relationships: Post
β οΈ Model Comment already exists, skipping...
β
Successfully generated 5 models!
β
Updated 2 existing models with relationships!
π Models location: /path/to/app/Models
| Feature | This Package | krlove/eloquent-model-generator | reliese/laravel | |---------|--------------|----------------------------------|-----------------| | Beautiful UI | β | β | β | | Model Updates | β | β | β | | Multi-DB Support | β | β | β | | Relationships | β | β | β | | PHPDoc Generation | β | β | β | | Zero Configuration | β | β | β | | Many-to-Many Detection | β | β | β |
If you discover any issues, please use the GitHub issue tracker.
--force option only adds missing propertiesβ Star us on GitHub if this package helped you!
π Happy coding!