romanzipp/laravel-model-doc
Laravel Model Doc automatically generates PHPDoc annotations for your Eloquent models from the database schema, keeping IDE autocompletion and static analysis accurate. It saves you from manually maintaining model property docblocks as tables evolve.
composer require --dev romanzipp/laravel-model-doc
php artisan vendor:publish
# select the model-doc provider/tag from the list
php artisan model-doc:generate
# or target one model if the command supports it:
php artisan model-doc:generate --model=User
app/Models/User.php and inspect the generated docblock. You should see @property entries for columns and @property-read entries for relations, e.g.:
/**
* @property int $id
* @property string $email
* @property-read Collection|Post[] $posts
*/
class User extends Model {}
Where to look first: the published config file, php artisan model-doc:generate --help, and the diff in one small model before running it across the whole app.
php artisan migrate or a schema edit, run the generator and commit the docblock diff. Treat generated annotations like compiled artifacts: regenerate locally, review, commit.git diff --exit-code to fail if generated docblocks are stale. If the command exposes a --check flag, prefer that.barryvdh/laravel-ide-helper:models can also generate model docblocks. Pick one source of truth for @property annotations to avoid conflicting/duplicated blocks. Use model-doc for attributes/relations and IDE Helper for facades/helpers if needed.$user->email from mixed into string, and $user->posts into Collection<int, Post>, which materially improves analysis results.public function posts(): HasMany
{
return $this->hasMany(Post::class);
}
The generator relies on return types and relation calls. For custom keys, polymorphic relations, or hasManyThrough, verify the generated annotation and patch manually if needed.@property-read vs @property, ordering, spacing). Keep custom templates in version control, not in vendor/.app/Models, configure multiple paths or run the command per module. Keep generated annotations close to the models they describe."scripts": {
"model-doc": [
"@php artisan model-doc:generate"
]
}
json, enum, unsignedBigInteger, etc.).mixed, array). Add precise @property annotations manually for those, or extend the generator if it supports custom type mapping.mixed/array. Refine manually if static analysis matters.@property-read lines for every relation and patch the exceptions.php artisan config:clear. Do not run config:cache before generation in CI.-v and check permissions on app/Models.composer.json, review changelogs, and keep a wrapper script so you can swap tools later..gitattributes. Use the CI drift check to keep them fresh.How can I help you explore Laravel packages today?