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.
Developer Experience (DX) & Productivity:
routes/web.php or routes/api.php.API/Backend Roadmap:
Use Cases:
Route::get() definitions to attributes in large codebases.darkaonline/l5-swagger) to auto-generate API docs from attributes.#[Middleware('auth:sanctum')] or custom attributes for declarative route policies.Architectural Decisions:
routes/*.php files, centralizing logic in controllers.#[RouteTest] annotations for test suites).Adopt When:
routes/*.php).Look Elsewhere If:
"This package lets our backend team define API routes directly in controller methods using PHP attributes—eliminating repetitive route boilerplate in routes/*.php files. It’s like moving route definitions closer to the business logic they serve, which speeds up development, reduces errors, and makes the codebase easier to navigate. For example, a new endpoint can be added in seconds without touching route files. It’s a low-risk, high-reward DX improvement that aligns with modern PHP practices and could reduce technical debt in our API layer."
Key Outcomes:
*"This replaces manual Route::get() calls with attributes like #[Get('path')], auto-registering routes at runtime. Benefits:
Trade-offs:
Proposal: Pilot this in [Module Y] to compare DX with our current approach. If successful, we can roll it out to new APIs and gradually migrate existing ones."*
Visual Hook:
"Imagine routes/api.php shrinking from 500 lines to 50, with routes defined next to their logic—like how React routes work with Route components."
How can I help you explore Laravel packages today?