routes/web.php/routes/api.php, improving modularity for microservices or monolithic apps with domain-driven separation.where clauses, avoiding reinvention while adding attribute-driven flexibility.php artisan route:cache) or third-party packages (e.g., spatie/laravel-permission) that rely on manual route registration.Route::get()) may require incremental adoption or hybrid approaches (e.g., attribute + traditional routes).auth:api)./v1/users) compared to traditional route prefixes?tinker or route:list commands when using attribute discovery?Route::model() equivalents via attributes).Phase 1: Greenfield Adoption
@Route attributes exclusively.routes/*.php with attribute-based discovery in app/Http/Controllers.config/router.php to define global conventions (e.g., base URI, excluded namespaces).Phase 2: Legacy Hybrid
Route::ignore() or middleware to exclude traditional routes from attribute discovery.// app/Http/Controllers/UserController.php
#[Route('users', ['middleware' => 'auth:sanctum'])]
class UserController extends Controller { ... }
Phase 3: Full Migration
Route::* calls from routes/*.php.app/Providers/RouteServiceProvider to delegate discovery entirely to the package.php artisan route:cache (verify compatibility).spatie/laravel-permission). Test with:
laravel/api-resources).Route::macro() definitions.RouterServiceProvider loads after third-party providers that modify routes./dashboard, /settings) before migrating public/API endpoints.php artisan route:list --path="*" to verify attribute-discovered routes appear correctly.auth, throttle) on attribute-routed controllers.php artisan tinker and under load (e.g., Laravel Forge/Ptero).RouterServiceProvider binding).Route::get/put(...) calls.config/router.php) simplify global changes.@Route('posts/{post}', ['bind' => Post::class])).route:list output).php artisan route:list --json | jq '.length').Poshtive\Router logs for skipped/duplicate route warnings.laravel-debugbar or Blackfire.routes/*.php.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Attribute parsing error | Routes fail to register | Use try-catch in boot() to log errors without crashing. |
| Duplicate route detection false + | Silent route overrides | Enable skipped_routes_reporting in config and monitor logs. |
| Middleware conflict | Broken auth/validation | Test with php artisan route:list --with-middleware. |
| Package update breaks conventions | Route misconfiguration | Pin version in composer.json until stability is proven. |
| Reflection performance bottleneck | Slow boot time | Profile with Xdebug; exclude non-critical namespaces from discovery. |
| IDE attribute recognition issues | Poor developer experience | Add PHPDoc annotations or contribute to Laravel IDE Helper support. |
assertRouteExists() helpers).How can I help you explore Laravel packages today?