Laravel - How to disable session for specific route?

Viewed 87

Session driver is set to database currently. Now I want to disable session for some route. I am using laravel 7 in my project. What is the best way to disable the session?

I have tried: in StartSession.php file: \Config::set('session.driver', 'array');

Seems like it doesn't work for me, is there any better way?

1 Answers

Trying to modify code in files within vendor directory is not a good practice as it will get overridden whenever the package is updated.

If you want to remove a middleware from a specific route you can use withoutMiddleware

Route::get('/some-endpoint', function () {
        //
    })->withoutMiddleware([StartSession::class]);

Laravel Docs - Middleware - Excluding Middleware

Related