在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:01:13  来源:igfitidea点击:

Disable session in Laravel

phpsessionlaravellaravel-5

提问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.phpI have also removed SESSION_DRIVEfrom .envfile. 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\VerifyCsrfTokenand Illuminate\View\Middleware\ShareErrorsFromSessionclasses from your middleware too. These features require sessions.

Illuminate\Foundation\Http\Middleware\VerifyCsrfTokenIlluminate\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 数组中,因此一旦请求完成,所有内容都会被删除。