Laravel
Eloquent models
PHP autodoc-laravel understands your database models and uses them to accurately document your API responses and TypeScript types.
Example
return response()->json([
'user' => User::find(1),
]);
To see more examples, check out the Routing section.
Relations
Currently these types of relations are supported: BelongsTo, BelongsToMany, HasMany, HasManyThrough, HasOne, HasOneThrough.
To correctly read your relation types, there must be a return type PHPDoc annotation with related model template type specified above the relation method. Example:
/**
* @return HasMany<Document, $this>
*/
public function documents(): HasMany
{
return $this->hasMany(Document::class);
}
If you are using a tool like PHPStan/Larastan, chances are you already have these annotations in place.
Serialization
The EloquentModel extension, provided by PHP autodoc-laravel, prevents reading properties like autodoc would from a regular class, but instead will check for a toArray method, and if not found on the model, will read properties from columns of the associated database table.
This extension also offers support for casts, appended and visible/hidden properties.