LaravelPackages.net
Acme Inc.
Toggle sidebar
amranibrahem/laravel-model-generator

Automatically generate Eloquent models from database tables with professional PHPDoc, relationships, and multi-database support

22
0
v2.1.2
About amranibrahem/laravel-model-generator

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

Laravel Model Generator

πŸš€ 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.

✨ Features

  • βœ… Auto-generate Eloquent models from database tables
  • βœ… Professional PHPDoc with type hints and relationships
  • βœ… Automatic relationship detection (hasMany, belongsTo, belongsToMany)
  • βœ… Multi-database support (MySQL, PostgreSQL, SQLite)
  • βœ… Smart model updating without overwriting custom code
  • βœ… Custom namespaces and paths
  • βœ… Beautiful console output with emojis
  • βœ… Fillable properties & casting generation
  • βœ… Table name singularization
  • βœ… Many-to-Many relationships detection

πŸš€ Installation

You can install the package via Composer:

composer require amranibrahem/laravel-model-generator

πŸ“– Usage

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

🎯 Examples

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');
  }
}

βš™οΈ Options

| 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 |

πŸ”§ Supported Databases

  • MySQL - Full support with foreign key detection
  • PostgreSQL - Complete support with schema information
  • SQLite - Basic support with table info

🎨 Console Output

πŸš€ 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

⚑ Comparison with Alternatives

| 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 | βœ… | ❌ | βœ… |

πŸ› Reporting Issues

If you discover any issues, please use the GitHub issue tracker.

πŸ† Credits

πŸ’‘ Why Use This Package?

  • Save Development Time - Generate models in seconds instead of hours
  • Reduce Errors - Automatic relationship detection prevents mistakes
  • Professional Code - PHPDoc and proper Laravel conventions
  • Flexible - Works with existing projects and new ones
  • Safe Updates - --force option only adds missing properties
  • Multi-Database - Works with MySQL, PostgreSQL, and SQLite

⭐ Star us on GitHub if this package helped you!

πŸš€ Happy coding!

Comments