Laravel
Routing
PHP autodoc-laravel integrates with Laravel routes, supporting route parameters, model bindings, and enum bindings for accurate API documentation.
Example 1
Route::get('/client/{id}', function (string $id) {
// ...
})->whereUuid('id');


Example 2
This example demonstrates implicit route model binding. PHP autodoc-laravel automatically resolves the key type using the model’s route key name.
When there is no @return
PHPDoc tag on the method, autodoc-laravel attempts to infer the return type by analyzing the method body. In this case, it returns a Rocket model with a hidden id
property.
Route::get('/rocket/{rocket}', [
RocketController::class,
'findById',
]);
public function findById(Rocket $rocket): mixed {
return $rocket;
}
class Rocket extends Model
{
protected $hidden = ['id'];
}
/**
* Note: PHP autodoc-laravel does not parse your migrations
* directly, it reads the columns from your DB schema.
*/
Schema::create('rockets', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->date('launch_date');
$table->timestamps();
});


You can read more about how autodoc-laravel handles models in the Eloquent models section.
Example 3
You can add descriptions for your route path parameters using @param
PHPDoc tags.
Route::post(
uri: '/rocket/{rocketId}',
action: [RocketController::class, 'findById']
);
/**
* @param int $rocketId Description of the rocket identifier.
*/
public function findById(Request $request, int $rocketId) {
$rocket = Rocket::find($rocketId);
return response()->json([
'id' => $rocket->id,
'name' => $rocket->name,
'launch_date' => $rocket->launch_date,
]);
}


Example 4
This example demonstrates implicit route model binding with a custom key (launch_date
on the Rocket model), as well as implicit enum binding for the RocketCategory.
Route::get(
uri: '/rocket/{category}/search/{rocket:launch_date?}',
action: function (
RocketCategory $category,
Rocket $rocket = null,
): Rocket {
// ...
},
);
enum RocketCategory: string
{
case Big = 'big';
case Small = 'small';
}

