Route improvements are coming to Laravel 5.4

Tutorials

December 6th, 2016

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:

Eric L. Barnes

Eric is the creator of Laravel News and has been covering Laravel since 2012.