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 Backend Engineer
Remote
64 Robots
Senior Laravel Developer
Atlanta, GA
Helium LLC
Full-Stack Developer (JS - Vue.js, PHP - Laravel)
US Remote / Telecommute
TTEC Digital
Backend Engineer
Brooklyn, NY
Stationhead
Back-End Developer
Orlando, FL
Christ for all Nations
Senior Software Developer
Nashville, TN
Bernard Health
Full Stack PHP Developer – (Laravel & Vue.js) - local only
Salt Lake City, Utah
Swell