定制 boktoso-enterprise/laravel-model-doc 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

boktoso-enterprise/laravel-model-doc

Composer 安装命令:

composer require boktoso-enterprise/laravel-model-doc

包简介

Laravel Model PHPDoc Generator

README 文档

README

Fork off of romanzipp/Laravel-Model-Doc

Generate PHPDoc comments for Laravel Models including database columns, relationships, accessors, query scopes and factories.

Contents

Installation

composer require boktoso-enterprise/laravel-model-doc --dev

Configuration

Copy configuration to config folder:

php artisan vendor:publish --provider="boktoso-enterprise\ModelDoc\Providers\ModelDocServiceProvider"

Usage

php artisan model-doc:generate

See the configuration file for more specific use cases.

Prepare your models

  1. Add the corresponding table name
  2. Add relation methods return types
  3. Add accessor methods return types
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class MyModel extends Model
{
    protected $table = 'models'; // 1. Add the corresponding table name
    
    public function teams(): HasMany // 2. Add relation methods return types
    {
        return $this->hasMany(Team::class);
    }
    
    public function getNameAttribute(): string // 3. Add accessor methods return types
    {
        return ucfirst($this->name);
    }
}

Example

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * @property string $id
 * @property string $title
 * @property string $pretty_title
 * @property string|null $icon
 * @property int $order
 * @property bool $enabled
 * @property array $children
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 *
 * @property \Illuminate\Database\Eloquent\Collection|\App\Models\Team[] $teams
 * @property int|null $teams_count
 *
 * @method static \Illuminate\Database\Eloquent\Builder whereTeamName(string $name)
 * 
 * @method static \Database\Factoies\MyUserFactory<self> factory($count = null, $state = [])
 */
class MyUser extends Model
{
    use HasFactory;

    protected $table = 'users';

    protected $casts = [
        'children' => 'array',
    ];

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

    public function scopeWhereTeamName(Builder $builder, string $name)
    {
        $builder->where('name', $name);
    }

    public function getPrettyTitleAttribute(): string
    {
        return ucfirst($this->title);
    }
    
    protected static function newFactory()
    {
        return new \Database\Factoies\MyUserFactory();
    }
}

Set custom path

You can set a custom base path for the generator using the usePath static method.

use Illuminate\Support\ServiceProvider;
use BoktosoEnterprise\ModelDoc\Services\DocumentationGenerator;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        DocumentationGenerator::usePath(fn () => base_path('app/Models'));
    }
}

See the configuration file for more specific use cases.

Use verbose mode

If you get an error when generating the documentation for a model, you can use the --v option to get more information about the error.

php artisan model-doc:generate -v

Specify the Model to update

If you get an error when generating the documentation for a model, you can use the --v option to get more information about the error.

php artisan model-doc:generate --model={modelClass}

Custom database types

If (in verbose mode) you get an error like Unknown database type enum requested, you can add that custom type mapping in Laravel's database.php config file. Laravel uses the Doctrine DBAL package for database types. You can find a list of supported types here. Laravel provides an example for timestamp type mapping here.

Here is an example for enum type mapping in database.php config file:

'dbal' => [
    'types' => [
        'enum' => Doctrine\DBAL\Types\StringType::class,
    ],
],

Testing

SQLite

./vendor/bin/phpunit

MariaDB

Requires Lando.

lando start
lando phpunit

boktoso-enterprise/laravel-model-doc 适用场景与选型建议

boktoso-enterprise/laravel-model-doc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.84k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-03