Laravel Model Annotator is a developer tool that automatically adds PHPDoc annotations to your Eloquent model classes based on your database schema. It improves IDE autocompletion and static analysis for properties, relationships, and casted attributes and now export full model documentation to a markdown file.
- ✅ Annotates all model properties based on database columns.
- 🔁 Detects and documents Eloquent relationships (
hasMany
,belongsTo
, etc). - 🧠 Adds annotations for casted attributes using Laravel's
$casts
. - ✨ IDE-friendly annotations for better autocompletion and PHPStan support.
- 🪄 Works out of the box — just install and run.
If published to Packagist:
composer require dottedai/laravel-model-annotator --dev
- Clone or download the repository into a
packages
directory:
mkdir -p packages/dottedai
git clone https://github.com/dottedai/laravel-model-annotator packages/dottedai/laravel-model-annotator
- Add to your
composer.json
:
"repositories": [
{
"type": "path",
"url": "packages/dottedai/laravel-model-annotator"
}
]
- Require it locally:
composer require dottedai/laravel-model-annotator:*
After installation, run the Artisan command:
php artisan models:annotate
This will scan the app/Models
directory and update each model class with a PHPDoc block containing:
@property
for columns (with types and nullability),@property
for relationships,@property
for casted attributes.
/**
* @property int $id
* @property string $name
* @property string|null $email
* @property \App\Models\Team $team
* @property Carbon\Carbon $created_at
*/
class User extends Model
php artisan models:export-docs
Generates a MODEL_DOCS.md
in the root directory with all properties, casts, and relationships grouped by model.
# Eloquent Model Annotations
## User
### Properties
- `int $id`
- `string $name`
- `?string $email`
### Casts
- `datetime $created_at`
### Relationships
- `\App\Models\Team $team`
By default:
- Scans
app/Models
. - Infers column types and nullability from DB schema.
- Detects relationship methods with no arguments.
- Reads
$casts
array from the model.
- Uses Laravel’s Schema Builder to inspect each model’s database table.
- Reflects on model methods to identify Eloquent relationships.
- Combines schema and relationship data into a single annotation block.
- Rewrites the top of the model file with the updated docblock.
- PHP 8.0+
- Laravel 9, 10, or 11
This project is open-sourced under the MIT license.