承接 patressz/laravel-model-documenter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

patressz/laravel-model-documenter

Composer 安装命令:

composer require --dev patressz/laravel-model-documenter

包简介

A Laravel package for generating model documentation.

README 文档

README

Tests

A simple Laravel package for automatic generation of PHPDoc comments for Eloquent models. The package automatically analyzes database columns, relations, accessors, and scope methods of your models and generates properly typed PHPDoc annotations.

Requirements

  • PHP 8.3+
  • Laravel 11.0+

Installation

Install the package via Composer:

composer require patressz/laravel-model-documenter --dev

Usage

Basic Usage

Generate documentation for all models in the app/Models directory:

php artisan model-doc:generate

Specific Model

Generate documentation for a specific model only:

php artisan model-doc:generate --model=App\\Models\\User

Custom Directory

Specify a custom directory containing models:

php artisan model-doc:generate --path=/path/to/your/models

Compare existing documentation with expected documentation (without modifying files):

php artisan model-doc:generate --test

What it Generates

The package automatically generates PHPDoc annotations for:

  • Database columns - @property with correct types based on database schema
  • Casts - Automatically detects model casts and overrides database types with cast types (e.g., datetime, array, json, boolean)
  • Relations - @property-read for all relation types (hasOne, hasMany, belongsTo, etc.) - Note: Only generates properties for relationship methods that have proper return type declarations (e.g., HasMany, BelongsTo)
  • Accessors/Mutators - @property, @property-read or @property-write depending on type (supports both old-style and new Attribute-based accessors)
  • Local Scope methods - @method annotations for scope methods

Example Output

For a User model with a table containing id, name, email, email_verified_at columns, casts, and a posts() relation:

use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Model;

/**
 * @property int $id
 * @property string $name
 * @property string $email
 * @property ?\Illuminate\Support\Carbon $email_verified_at
 * @property array<array-key, mixed> $settings
 * @property ?\Illuminate\Support\Carbon $created_at
 * @property ?\Illuminate\Support\Carbon $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Post> $posts
 * 
 * @method static \Illuminate\Database\Eloquent\Builder<static>|User active()
 */
class User extends Model
{
    protected $casts = [
        'email_verified_at' => 'datetime',
        'settings' => 'array',
    ];

    // your model code...

    public function posts(): HasMany
    {
        return $this->hasMany(Post::class);
    }

    public function scopeActive($query)
    {
        return $query->where('active', true);
    }
}

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固