Laravel 11 does not come with a middleware file and the kernel.php file has been removed altogther. So, when I create a custom middleware, how do I register it?
I do not know where to register middleware. Laravel 11 has been very confusing.
Laravel 11 does not come with a middleware file and the kernel.php file has been removed altogther. So, when I create a custom middleware, how do I register it?
I do not know where to register middleware. Laravel 11 has been very confusing.
2
Answers
in kernel.php file
insert middleware class name
In laravel 11 you can not register in the kernel.php the middlewares anymore. However there is plenty of other way how you can register the middlewares.
If you want it to be triggered in every call you can append it to the
bootstrap/app.php
.Otherwise you can add middlewares to specific route or route groups:
If you add a middleware to a route group but you dont want certain routes to trigger the middleware, you can use the
withoutMiddleware
methodFor more information check out the official documentation: https://laravel.com/docs/11.x/middleware#registering-middleware