jasonlewis/enhanced-router
Enhanced Router extends Laravel's native routing layer with extra conveniences for cleaner, more expressive route definitions. It helps organize routes and keep larger applications maintainable while preserving the familiar Laravel routing API.
Install via Composer, pinning to the 1.x line (the package was abandoned in 2013 and has no later releases):
composer require jasonlewis/enhanced-router:1.0.*
This is a router replacement, not an add-on. In app/config/app.php, comment out Laravel's default Illuminate\Routing\RoutingServiceProvider and register the package's provider instead — do not register both, or you'll end up with two routers bound in the container and confusing resolution behaviour:
'providers' => array(
// 'Illuminate\Routing\RoutingServiceProvider',
'JasonLewis\EnhancedRouter\EnhancedRouterServiceProvider',
),
Where to look first. Read the three classes you'll actually be touching — everything else is Laravel 4 plumbing:
src/JasonLewis/EnhancedRouter/Router.php — subclasses Illuminate\Routing\Router; this is the object Route:: resolves to.src/JasonLewis/EnhancedRouter/Route.php — the enhanced route object (group attribute handling, cache serialization).src/JasonLewis/EnhancedRouter/RouteCollection.php — ordering and the compiled-route loading path.First real use case. On a large app with a few hundred routes, the biggest daily win is route caching: the collection is compiled to a PHP file and loaded on boot instead of re-executing app/routes.php (and its closures/Route:: calls) on every request. Get a working routes.php first, verify with php artisan routes, then turn caching on.
The core value is that group attributes actually merge — prefix, domain, before/after filters, and where patterns stack predictably through nested groups, which core Laravel 4 handled inconsistently:
Route::group(['prefix' => 'admin', 'before' => 'auth'], function () {
Route::group(['domain' => '{account}.example.com', 'before' => 'account'], function () {
Route::get('dashboard', 'AdminController@dashboard')
->where('account', '[a-z0-9\-]+');
});
});
Sub-domain parameters ({account}.example.com) are treated like any other route parameter, so they participate in where() constraints and are appended to the controller action arguments. Bind them early (in a before filter) so downstream filters can rely on them.
Route::cache() call from your bootstrap, depending on the version) to write the compiled collection to storage.Rather than one giant routes.php, split by concern (routes/admin.php, routes/api.php, routes/web.php) and load them from the main file. Keeps diffs reviewable and lets you cache a stable set of files.
Apply where() once for a set of routes via group attributes instead of repeating it per route — this is the pattern that saves the most typing day-to-day.
Route::get('/', function () {...}). Convert closure routes to controller actions before enabling the cache — this is the single most common onboarding failure with this package.routes.php entirely. If a route "doesn't exist" after you added it, clear/rebuild the route cache before debugging anything else.route:cache. 4.2 shipped its own route cache; running both produces two competing compiled collections and unpredictable order. Pick one — on 4.2, prefer the core one and only use this package for the group/domain features.Illuminate\Routing\Router gets the core binding unless it resolves the router alias. If a third-party package behaves oddly, check which router instance it received.composer update on the framework is a breaking change.JasonLewis\EnhancedRouter\Router, override the relevant method, and rebind router in your own service provider — cheaper than patching vendor/.Route::getRoutes() (the enhanced collection) and inspect the compiled cache file on disk; comparing the two immediately shows whether you're running against a stale build.How can I help you explore Laravel packages today?