Laravel 8 Package Development pushMiddlewareToGroup

Viewed 157

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 Answers

Did you wrap the code in booted?

$this->app->booted(function () {
    $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

Related