Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laminas Router

Laminas Router Laravel Package

laminas/laminas-router

Laminas Router provides flexible HTTP routing for PHP apps. Build routes from config or code, match incoming requests to controllers/handlers, and assemble URLs from route names and parameters. Supports segment, literal, regex, and more route types.

Deep Wiki
Context7

laminas/laminas-router is a flexible routing component for PHP applications, providing robust tools to match incoming HTTP requests to controllers, middleware, or handlers. It supports a variety of route types and composition patterns, making it suitable for both small apps and complex modules with evolving URL structures.

Designed for clarity and extensibility, Laminas Router integrates cleanly with Laminas MVC and other PSR-friendly stacks, enabling precise, maintainable route definitions.

  • Multiple route types (literal, segment/parameterized, regex, hostname, and more)
  • Composable routing with child routes and hierarchical definitions
  • Route assembling to generate URLs from route names and parameters
  • Constraints & defaults for safe parameter matching and fallback behavior
  • Extensible architecture to add custom route implementations
Frequently asked questions about Laminas Router
Can I use Laminas Router directly in Laravel without extra packages?
No, Laminas Router isn’t designed for Laravel’s native routing system. It’s built for PSR-7 middleware stacks like Mezzio or Laminas MVC. You’d need a bridge package (e.g., `laminas/laminas-router-glob`) or rewrite routes manually, which isn’t recommended for production.
What Laravel alternatives offer similar routing flexibility?
For Laravel, consider `spatie/laravel-honeypot` (for route-based honeypots), `spatie/laravel-route-tools` (for route caching), or Laravel’s built-in router with `Route::group()` for nested routes. For PSR-7 style, try `php-di/http-router` or `fastroute/fast-route`.
Does Laminas Router support Laravel’s route caching?
No, Laminas Router doesn’t integrate with Laravel’s route caching (`php artisan route:cache`). It’s optimized for dynamic, middleware-driven routing. If you need caching, pair it with a Laravel-compatible package like `spatie/laravel-route-tools` or use Laravel’s native router.
How do I install Laminas Router in a Laravel project?
Run `composer require laminas/laminas-router`, but note this won’t auto-configure Laravel routes. You’d need to manually bind it to Laravel’s service container (e.g., in `AppServiceProvider`) and override the router, which is complex and not officially supported. Test thoroughly in a staging environment first.
Will Laminas Router work with Laravel’s API resources?
Not natively. Laminas Router lacks Laravel’s API resource conventions (e.g., `Route::apiResource()`). You’d need to define routes manually using its segment/literal syntax, which defeats Laravel’s built-in API scaffolding. For APIs, stick to Laravel’s router or use `dingo/api` for advanced needs.
Can I use Laminas Router for console commands in Laravel?
Yes, but with limitations. Laminas Router supports console routes, but Laravel’s Artisan commands use a different dispatch system. You’d need to integrate it via a custom command resolver, which isn’t straightforward. For console routing, Laravel’s native `Route::console()` or `laravel-zero/laravel-zero` are better choices.
Does Laminas Router support regex route matching like Laravel?
Yes, Laminas Router supports regex matching via `Regex` route types, similar to Laravel’s `where()` constraints. However, the syntax differs: Laravel uses `Route::get('/user/{id}', ...)->where('id', '[0-9]+')`, while Laminas uses `Regex('user/{id}', '/^user/([0-9]+)$/')`. Test regex performance in production—Laminas’ regex engine may not be optimized for Laravel’s scale.
Is Laminas Router actively maintained for Laravel compatibility?
No, Laminas Router is maintained for the Laminas ecosystem (PSR-7, Mezzio). Laravel compatibility isn’t a priority. The package’s last major update focused on Laminas 4.x, and breaking changes may occur without Laravel-specific fixes. Check the [Laminas GitHub](https://github.com/laminas/laminas-router) for deprecations.
How do I handle middleware with Laminas Router in Laravel?
Laminas Router integrates with PSR-15 middleware, but Laravel uses its own middleware stack. You’d need to bridge them via a custom `MiddlewareDispatcher` or use `psr/http-message` adapters, which adds complexity. For Laravel, use `Route::middleware()` or packages like `fruitcake/laravel-cors` for middleware-heavy routes.
What’s the performance impact of using Laminas Router in Laravel?
Laminas Router is optimized for Laminas’ lightweight stack, not Laravel’s heavyweight services. Expect slower route matching due to PSR-7 overhead (e.g., request/response objects). Benchmark with `phpbench/phpbench` in staging—if latency exceeds 10ms per request, consider Laravel’s native router or `fastroute/fast-route` for a drop-in replacement.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport