Registering Middleware in Laravel 5.4 using aliasMiddleware
Feb 17, 2017Registering a new custom middleware on Laravel from service provider is too easy. Previously while working on Laravel 5.3 you could register a middleware by calling the middleware
function.
When you call the above function, Laravel behind the hood calls the Router.php
file on Illuminate\Routing\Router
and calls the below function.
Above function simply registers the new middleware that you have passed through Route::middleware
function on service provider.
Introducing aliasMiddleware
On Laravel 5.4, this middleware function has been renamed as aliasMiddleware
.
So, on Laravel 5.4 you must register a middleware using the aliasMiddleware like the following
Happy Coding!