Route improvements are coming to Laravel 5.4

Route improvements are coming to Laravel 5.4

As Laravel 5.4 development continues, two new improvements are coming to your routes, better route caching for large applications and fluently registering routes.

Route Caching Improvements

The route caching layer contains improvements that will allow route matching on very large applications to see a significant improvement. In this context very large is applications with more than one thousand routes defined.

Fluent Registering Routes

In the past, if you wanted to define a named route or a middleware you would do it like this at the end of the closure:

Route::get('user/{id}/profile', function ($id) {
    //
})->name('profile');

Now you can define it at the beginning:

Route::name('profile')->get('user/{id}/profile', function ($id) {
    // some closure action...
});

Joseph Silber created the pull request to add this feature, and he outlined a few other examples of utilizing this new option:

Registering a route name and a middleware

Route::name('users.index')->middleware('auth')->get('users', function () {
    // some closure action...
});

Registering a middleware with a route prefix and group

Route::middleware('auth')->prefix('api')->group(function () {
    // register some routes...
});

Registering a middleware to a resource controller

Route::middleware('auth')->resource('photo', 'PhotoController');


Filed in: Laravel 5.4 / Routing


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Full-Stack Developer (PHP+JS)
Remote
The Interaction Design Foundation
Senior Laravel Developer
Remote
Sonar
Laravel / Vue.JS Developer - Join an amazing team!
Remote
JTR Solutions
Mid / Sen. Software Engineer
Clearwater, FL
ShineOn
Remote PHP / Laravel Developer
Remote
SpringboardVR
Senior PHP/Laravel Developer: Your Dream Work Environment
Remote
iPhone Photography School
Senior Laravel Developer
Leidseplein, Amsterdam
Orderchamp.com