Laravel 8 Package Development pushMiddlewareToGroup

555 Views Asked by At

After updating Laravel version from 6.0 to 8.0, the middleware pushed using $router->pushMiddlewareToGroup is not working.

//add language middleware to the web group
    $router->pushMiddleWareToGroup('web',Language::class);
1

There are 1 best solutions below

0
bilogic On

Did you wrap the code in booted?

$this->app->booted(function () use ($router) {
    $router->pushMiddleWareToGroup('web',Language::class);  
});

I faced the same issue and it was resolved only after calling pushMiddleWareToGroup in booted. You might also want to set the loading priority using protected $middlewarePriority = [...]; in App\Http\Kernel.php