GitHub - sethsandaru/eloquent-docs: Generate phpDoc for your Eloquent Models with ease
Extracto
Generate phpDoc for your Eloquent Models with ease - GitHub - sethsandaru/eloquent-docs: Generate phpDoc for your Eloquent Models with ease
Contenido
Laravel Eloquent phpDoc Generator
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 types)
- Model relationships
- Model attributes/accessors
Available For / Requirements
- PHP 8.1 / 8.2
- Laravel 9 / 10
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:
====== 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!
Note: if you haven't installed doctrine/dbal as your dev-dependency,
then once you trigger the command for the first time, it will help you to install the needful dependency
Best practices
- Use
$castsin your model, in order to help EloquentPhpDoc generate better types for you (array, Carbon,...) - For
get*Attributeaccessor, always declare the return type
Note: Eloquent new Attribute class utilize the data via Closure, thus we can't declare any return type for any attributes.
For this case, EloquentPhpDoc 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.
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
Fuente: GitHub