I have not found the function to add/create a middleware group, but these are the other ways I found to add middleware in a service provider.
public function boot( Illuminate\Routing\Router $router, \App\Http\Kernel\Kernel $kernel) {
// Add a new middleware to beginning of the stack if it does not already exist.
$kernel->prependMiddleware(\path\to\custom\middleware\file::class)
// Add a new middleware to end of the stack if it does not already exist.
$kernel->pushMiddleware(\path\to\custom\middleware\file::class)
// Get or set the middlewares attached to the route.
$router->middleware(\path\to\custom\middleware\file::class)
}
TerrePorter said:
I have not found the function to add/create a middleware group, but these are the other ways I found to add middleware in a service provider.
public function boot( Illuminate\Routing\Router $router, \App\Http\Kernel\Kernel $kernel) { // Add a new middleware to beginning of the stack if it does not already exist. $kernel->prependMiddleware(\path\to\custom\middleware\file::class) // Add a new middleware to end of the stack if it does not already exist. $kernel->pushMiddleware(\path\to\custom\middleware\file::class) // Get or set the middlewares attached to the route. $router->middleware(\path\to\custom\middleware\file::class) }
Thank you for your replay. I found the solutions too, but it seems I need some workaround about it or wait till middleware group register functions will appear in router class.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community