spatie/laravel-route-attributes
Register Laravel routes using PHP 8 attributes on controller methods (Get/Post/etc.). Automatically scans configured controller directories and registers routes without manual Route:: definitions. Includes config publishing and optional enabling/disabling of auto registration.
Route:: definitions).Route:: definitions until IDEs fully support PHP 8 attributes.php artisan route:cache).Route:: definitions in new features while keeping legacy routes for backward compatibility.Route::getRoutes() to verify attribute-routed endpoints are registered correctly.Route:: definitions.route:cache works seamlessly with attribute routes (test in staging).php artisan route:list + route:cache.)routes/web.php.UserController handles /users).Route:: macros.RouteServiceProvider or custom route registration logic./dashboard routes) to attributes.php artisan route:list).auth, throttle) applies as expected.Route:: definitions in favor of attributes (document the change).RouteServiceProvider).#[Get('route', middleware: ['auth'])]).php artisan route:cache.Route::resource equivalents via attributes.throttle middleware.#[Get('users/{user}', bind: ['user'])]).route:list and route:cache behavior.routes/web.php or api.php → easier maintenance.use statements.#[Get(..., middleware: [...])]).php artisan route:clear) and test.php artisan route:list to verify routes.dd(Route::getRoutes()) to inspect the route collection.php artisan route:list (compare with/without attributes).route:cache mitigates reflection costs in production.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Attribute route not registered | 404 errors | Validate use statements, check for typos. |
| Middleware not applied | Unauthorized access | Test middleware assignment in attributes. |
| Route caching issues |
How can I help you explore Laravel packages today?