在Laravel中禁用会话

问题描述:

我正在开发无状态的Resful API应用程序,因此根本不需要会话.

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

我从\app\Http\Kernel.php中的protected $middleware = [];中删除了带有\Illuminate\Session\Middleware\StartSession::class,的行,也从.env文件中删除了SESSION_DRIVE.但我收到以下错误消息:

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.

如何关闭Laravel 5中的会话?

How can I turn off sessions in Laravel 5?

也从中间件中删除Illuminate\Foundation\Http\Middleware\VerifyCsrfTokenIlluminate\View\Middleware\ShareErrorsFromSession类.这些功能需要会话.

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

不是必需的,但我也可能建议将会话驱动程序设置为array,以便如果您使用的任何功能都需要会话功能,它们至少可以正常工作而不会引发错误.正如建议的那样,数组驱动程序将所有会话数据存储在标准的PHP数组中,以便在请求完成后立即擦除所有内容.

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.