在 Laravel 中禁用会话
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31589607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable session in Laravel
提问by user1292810
I am developing stateless resful API application, so I do not need sessions at all.
我正在开发无状态的 resful API 应用程序,所以我根本不需要会话。
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:
我删除了一行\Illuminate\Session\Middleware\StartSession::class,
from protected $middleware = [];
in\app\Http\Kernel.php
我也SESSION_DRIVE
从.env
文件中删除了。但我收到以下错误:
RuntimeException in Request.php line 756: Session store not set on request.
How can I turn off sessions in Laravel 5?
如何关闭 Laravel 5 中的会话?
回答by Wader
Remove the Illuminate\Foundation\Http\Middleware\VerifyCsrfToken
and Illuminate\View\Middleware\ShareErrorsFromSession
classes from your middleware too. These features require sessions.
Illuminate\Foundation\Http\Middleware\VerifyCsrfToken
也Illuminate\View\Middleware\ShareErrorsFromSession
从中间件中删除和类。这些功能需要会话。
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.
不是必需的,但我也可能建议将您的会话驱动程序设置为array
,这样如果您使用的任何功能需要会话功能,它们至少可以工作而不会引发错误。正如它所建议的那样,数组驱动程序将所有会话数据存储在一个标准的 PHP 数组中,因此一旦请求完成,所有内容都会被删除。