New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

wenjy/laravel-model-gen

laravel 模型生成
4,020 6

Larablocks Analysis

wenjy/laravel-model-gen works with Laravel 7 to 10 (latest release v1.0.9, Jul 4, 2024), all past end of life (the last on Feb 4, 2025): no more fixes, even for security.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 7 to 10, past end of life since Feb 4, 2025
  • No release in the last 12 months (last: Jul 4, 2024)
  • 47 downloads a month (needs 10,000)
  • 6 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Jul 4, 2024.
  • No releases in the last 12 months.
  • First released: Jan 31, 2024.
  • Monthly downloads: 47.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 29, 2026.

Install
composer require wenjy/laravel-model-gen
Latest Version:v1.0.9
PHP:>=7.4
Laravel:7 – 10
License:MIT
Last Updated:Jul 4, 2024
Links: GitHub  ·  Packagist
Maintainer: wenjy

Laravel Model Generator

参考 YII的 model generator

使用说明

  • 引入包
composer require --dev wenjy/laravel-model-gen
  • 执行生成
php artisan gen:model [--table=] [--model=] [--conn=] [--ns=]

参数表名:--table 不传入表名,默认生成所有表的model,例如 --table=test_comments

参数模型类名:--model,例如 --model=TestAbc 不传入模型类名,使用表名单数大驼峰命名方式

参数数据库连接名:--conn,例如 --conn=test_conn 不传入数据库连接名,使用默认的数据库连接

参数命名空间:--ns,例如 --ns=App\Models\Tests 不传入命名空间,默认使用 App\Models,

  • 举例

test_comments 表结构为:

CREATE TABLE `test_comments` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `title` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '评论标题',
    `post_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '文章ID',
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    `aaa` decimal(10,0) NOT NULL DEFAULT '0',
    `v` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `w` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'aaaa',
    `a` text COLLATE utf8mb4_unicode_ci COMMENT 'json aa',
    `json1` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'json 1',
    `json2` json DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='测试评论表';

执行 php artisan gen:model --table=test_comments

会生成文件TestComment

<?php
/**
 * @date: 2024-02-04 05:39:19
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;


/**
 * This is the model class for table "测试评论表".
 * @property int $id
 * @property string $title 评论标题
 * @property int $post_id 文章ID
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @property string $aaa
 * @property string|null $v
 * @property string $w aaaa
 * @property array|null $a json aa
 * @property array|null $json1 json 1
 * @property array|null $json2
 */
class TestComment extends Model
{
    use HasFactory;

    /**
     * @var string
     */
    protected $table = 'test_comments';

    /**
     * @var array
     */
    protected $fillable = [
        'title',
        'post_id',
        'aaa',
        'v',
        'w',
        'a',
        'json1',
        'json2',
    ];

    /**
     * @var array
     */
    protected $casts = [
        'a' => 'array',
        'json1' => 'array',
        'json2' => 'array',
    ];
}

注意

laravel 8、laravel 9 只支持MySql(其它的数据库没有把SQL复制过来),laravel 10原生支持Schema::getColumns Schema::getTables()

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

670,032,257 9,703
laravel/framework

The Laravel Framework.

640,572,096 35,338
laravel/tinker

Powerful REPL for the Laravel framework.

546,909,908 7,440

Version History

Version Released PHP Laravel License
v1.0.9 >=7.4 ^7.0|^8.0|^9.0|^10.0 MIT
v1.0.8 >=7.4 ^7.0|^8.0|^9.0|^10.0 MIT
v1.0.7 >=7.4 ^8.0|^9.0|^10.0 MIT
v1.0.6 >=7.4 ^8.0|^9.0|^10.0 MIT
v1.0.5 >=7.4 ^8.0|^9.0|^10.0 MIT
Pre-releases (1)
Version Released PHP Laravel License
v1.0.0-beta1 >=7.4 ^8.0|^9.0|^10.0 MIT