Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dengdeng's avatar

Remove web middleware group in 5.2

I know that web middleware group is now assigned to every route. But how to remove for specific route?

0 likes
3 replies
SaeedPrez's avatar

@tomi I don't think that solution applies when dealing with global middlewares, that would work if you were applying middleware in the controller.

@dengdeng you probably need to remove the web middleware from being globally applied. What is the reason you don't want the web middleware?

SaeedPrez's avatar
Level 50

@dengdeng

So this got me curious enough to look into it a bit more, how to get around the global middlewares and I found the solution actually wasn't that complicated.

Just edit RouteServiceProvider.php and add your routes..

    /**
     * Define the routes for the application.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    public function map(Router $router)
    {
        $this->mapWebRoutes($router);

        // Add your routes here..
        $router->get('/foo', 'App\Http\Controllers\FooController@index');
    }

Please or to participate in this conversation.