In the Router class (Illuminate\Routing\Router), there is a pushMiddlewareToGroup method available. This works neatly for adding a middleware component to a specific group like web or api. However, I don't see any possibility to add a middleware component as global middleware. Two questions:
- Is my assumption that it is not possible to push middleware components to the global group correct?
- If so, is this a design decision?
CodePudding user response:
The global middleware are handled by the Kernel itself. The Kernel has methods for dealing with the global middleware such as pushMiddleware
:
$kernel = app(Illuminate\Contracts\Http\Kernel::class);
$kernel->pushMiddleware(App\Http\Middleware\YourMiddleware::class);