在Laravel中禁用会话 [英] Disable session in Laravel

查看:83
本文介绍了在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.

这篇关于在Laravel中禁用会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆