user1292810
user1292810

Reputation: 1822

Disable session in Laravel

I am developing stateless resful API application, so I do not need sessions at all.

I removed a line with \Illuminate\Session\Middleware\StartSession::class, from protected $middleware = []; in \app\Http\Kernel.php I have also removed SESSION_DRIVE from .env file. But I am getting following error:

RuntimeException in Request.php line 756: Session store not set on request.

How can I turn off sessions in Laravel 5?

Upvotes: 14

Views: 14427

Answers (1)

Wader
Wader

Reputation: 9868

Remove the Illuminate\Foundation\Http\Middleware\VerifyCsrfToken and Illuminate\View\Middleware\ShareErrorsFromSession classes from your middleware too. These features require sessions.

Not required but I'd also probably suggest setting your session driver to array, just so that if any features you are using require the sessions feature they can at least work without throwing errors. The array driver, as it suggests, stores all the session data in a standard PHP array so everything is erased as soon as the request is completed.

Upvotes: 26

Related Questions