amranibrahem/laravel-model-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

amranibrahem/laravel-model-generator

Composer 安装命令:

composer require amranibrahem/laravel-model-generator

包简介

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

README 文档

README

🚀 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

🔗 Links

⭐ Star us on GitHub if this package helped you!

🚀 Happy coding!

amranibrahem/laravel-model-generator 适用场景与选型建议

amranibrahem/laravel-model-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「generator」 「phpdoc」 「mysql」 「schema」 「sqlite」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 amranibrahem/laravel-model-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 amranibrahem/laravel-model-generator 我们能提供哪些服务?
定制开发 / 二次开发

基于 amranibrahem/laravel-model-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-24