sethphat/eloquent-docs
Composer 安装命令:
composer require sethphat/eloquent-docs
包简介
Generate PHPDoc scope for your Eloquent models (columns, accessors and more)
README 文档
README
Quickly generate the phpDoc for your Eloquent Model. Make your Eloquent super friendly with IDEs (eg PHPStorm).
And maintaining the phpDoc of your models don't have to be a pain in the ass, should be:
- Fun
- Fast
- Reliable
And, welcome to Eloquent phpDoc Generator, which going to help you to achieve the 3 points above 🎉
What will Eloquent phpDoc Generator will generate?
- Table name
- Table columns (with correct types - including Casting types 😎)
- Model relationships
- Model attributes/accessors
Available For / Requirements
- v2.x: Laravel 11, PHP 8.2+.
- v1.x: Laravel 9/10, PHP 8.0, 8.1.
Install
Install as dev-dependencies is enough, since you are only going to use this command on local/development env.
composer require sethphat/eloquent-docs --dev
Laravel auto-discovery will automatically do the magic for you.
Use the command
php artisan eloquent:phpdoc "App\Models\User" # view only php artisan eloquent:phpdoc "App\Models\User" --write # view & write to file php artisan eloquent:phpdoc "App\Models\User" --short-class # new option - use short class instead of full namespace path # from v1.2.0 php artisan eloquent:bulk-phpdoc "app/Models/*.php" # bulk generation (force write mode)
Result:
Details
====== Start PHPDOC scope of App\Models\User /** * Table: users * * === Columns === * @property int $id * @property string $name * @property string $email * @property \Carbon\Carbon|null|null $email_verified_at * @property string $password * @property string|null $remember_token * @property \Carbon\Carbon|null $created_at * @property \Carbon\Carbon|null $updated_at * * === Relationships === * @property-read \App\Models\Emails[]|\Illuminate\Database\Eloquent\Collection|null $emails * @property-read \App\Models\UserDetails|null $userDetail * * === Accessors/Attributes === * @property-read string $full_name * @property-read string $is_admin * @property-read string $user_type * @property-read int $total_salary * @property-read mixed $levels * @property-read mixed $first_name * @property-read mixed $last_name */ ====== End PHPDOC scope of App\Models\User Wrote phpDoc scope to /<my-path>/app/Models/User.php Thank you for using EloquentDocs!
Best practices
- Use
$castsin your model, in order to help EloquentPhpDoc generate better types for you (array, date, datetime,...) - For
get*Attributeaccessor, always declare the return type
Note: for Eloquent new Attribute class utilize the data via Closure, making it impossible to acquire the return types.
For this case, EloquentDocs will always return mixed
Release logs
- v1.0.0
- First version
- View & Update phpDoc for a single Model at a time
- v1.1.0
--short-class- Fixed some issues
- v1.1.1
- Fixed issue when generating a table that has
enumcolumn
- Fixed issue when generating a table that has
- v1.1.2
- Fixed issue when first-time install the library that made Laravel discovery went wrong.
- v1.1.3 & v1.1.4
- Improved the indents
- Supported Laravel 10
- Deprecated Laravel 8
- Deprecated PHP 8.0
- v1.2.0
- New command to bulk generate from a given model path.
php artisan eloquent:bulk-phpdoc "app/Models/*.php"
- Fixed an issue where accessors/attributes being generated as snake_case. Should be camelCase.
- New command to bulk generate from a given model path.
- v2.0.0
- Supports Laravel 11 + PHP 8.2/8.3
- DBAL as required dependencies
- Better date/datetime parsing (Carbon & Carbon immutable)
- Better boolean parsing
Contribute to the library
Feel free to fork this library and sending a PR here.
Note: all the contributions need to follow PSR-12 and cover everything under unit testing.
LICENSE
MIT License
Made by
- Seth Phat
- And contributors
(Sponsered Content) Introducing RenderPDF.io - Render your PDF in seconds
RenderPDF.io is a Render-PDF-as-a-Service that provides developer-friendly APIs to render your HTML content to modern PDFs file sin seconds 😎.
All you have to do is get your API Key and send RenderPDF.io an API call 🚀, no infrastructure setup, no overhead and hassle-free integration 🔋.
Get your free API Key today: Sign Up to RenderPDF.io
sethphat/eloquent-docs 适用场景与选型建议
sethphat/eloquent-docs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65.97k 次下载、GitHub Stars 达 53, 最近一次更新时间为 2022 年 08 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sethphat/eloquent-docs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sethphat/eloquent-docs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 65.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 53
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-21
