Reputation: 543
I know web
middleware group is assigned to every route now. But can someone tell me how to remove if for specefic route? I tried:
class HomeController extends Controller{
public function __construct(){
$this->middleware('web',['except'=>[
'index',
]]);
}
}
And it doesn't work.
Upvotes: 0
Views: 2944
Reputation: 6802
Web middleware is now applied to all routes in routes.php. This happens in the RouteServiceProvider map function.
If you have an api for example which should not use web middleware you can go with something like this
public function map(Router $router)
{
$this->mapWebRoutes($router);
$this->mapApiRoutes($router);
}
protected function mapWebRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace, 'middleware' => 'web',
], function ($router) {
require app_path('Http/routes.php');
});
}
protected function mapApiRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace, 'middleware' => 'api',
], function ($router) {
require app_path('Http/routes-api.php');
});
}
Now every route in routes.php has web middleware and everything in routes-api.php the api middleware
Upvotes: 1