Creating a Middleware alias

Submitted by laraning - 3 months ago

Sometimes you want to refer your custom middleware not by the full qualified namespace class, but only by an alias (E.g. like the ones that Laravel have created in the Middleware Kernel).

On your Service Provider boot() method:

app()->make('router')->aliasMiddleware('auth2', \Your\Namespace\Class\Auth2::class);

Then you can use it on your controllers or routes like:

Route::middleware('auth2') .... 

$this->middleware('auth2') ....


Hope it helps!

Bruno Falc√£o
www.laraning.com
comments powered by Disqus