illuminate/routing
Illuminate Routing provides Laravel’s URL generation and request routing layer, including route definitions, controllers, middleware, parameter binding, route caching, and named routes. Use it to match HTTP requests to actions with flexible, expressive APIs.
Begin by installing the package via Composer (composer require illuminate/routing). Since this is a subtree split of Laravel’s routing layer, it assumes Laravel’s ecosystem — even in standalone contexts. Start with bootstrapping the Router via Illuminate\Container\Container (e.g., $router = new Router($container = new Container)), then define and dispatch a route:
use Illuminate\Routing\Router;
use Illuminate\Http\Request;
$router = new Router($container = new Container);
$router->get('/ping', fn() => 'pong');
$request = Request::create('/ping', 'GET');
$response = $router->dispatch($request);
echo $response->getContent(); // "pong"
First explore Router and Route classes — they form the core API. Check RouteRegistrar for fluent route definition helpers (get(), post(), middleware(), etc.).
$router->group(['prefix' => 'api'], fn() => $router->get('/users', ...)) to share attributes. Chain middleware(), name(), where(), and conditional() via the returned RouteRegistrar instance.Route::bind('user', fn($slug) => User::where('slug', $slug)->first()), then use {user} in routes.$router->apiResource('posts', PostController::class) (or resource() for web routes).symfony/psr-http-message-bridge — e.g., wrap incoming PSR-7 request via Psr16Bridge, dispatch through router, then convert response back.$router->middlewareGroup('api', [ThrottleRequests::class]), then apply via ['middleware' => 'api'].UrlGenerator, ResponseFactory) cause cryptic errors — pre-bind: $container->singleton(UrlGenerator::class, fn() => new UrlGenerator(...)).route:cache Artisan command. Implement your own caching layer using Route::collectRoutes()->getRoutesByName() and Route::compile() — or skip caching unless performance-critical.$router->middleware()) or route-specific middleware (->middleware(...)) before route definition.$router->getRoutes()->get('GET', '/path') to verify route existence. Inside a closure, dd($router->getCurrentRoute()) helps diagnose mismatches.Router directly — use Laravel’s Tests\TestCase (which bootstraps the container) or mock Container and RequestStack precisely.illuminate/* dependencies must match Laravel 13. Upgrading one (e.g., illuminate/http) without others breaks routing. Lock versions strictly in composer.json.How can I help you explore Laravel packages today?