Laravel会话存储未按要求设置

时间:2015-11-04 09:11:52

标签: session laravel-5.1 runtimeexception

我正在开发一个小型网站,但会话有问题。当我尝试登录或进行AJAX调用时,我得到以下RuntimeException:

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

in Request.php line 758
at Request->session() in VerifyCsrfToken.php line 87
at VerifyCsrfToken->tokensMatch(object(Request)) in VerifyCsrfToken.php line 49
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Language.php line 38
at Language->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Language), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

知道我做错了什么。提前致谢

4 个答案:

答案 0 :(得分:1)

看看@Cas Bloem他的答案,这让我感到非常惊讶:

Laravel - Session store not set on request

这就是为什么它不适合我。因为你正在使用与CSRF令牌相匹配的会话(这是我最好的猜测,我自己是Laravel的新手)。

此外,如果您转到app-> http-> middleware-> VerifyCsrfToken,您可以添加路由到不会检查CSRF验证的阵列。这加上Cas Bloem他的修复(在routes.php的不同部分放置路由)解决了我的问题。我现在正在开发/学习localhost,但需要稍后实现。

希望这有助于/清除事情!

答案 1 :(得分:1)

假设您使用Laravel 5.2:如果您需要会话状态,CSRF保护等,您将需要使用Web中间件。 (就像5.1中的全球一样)

Route :: group([' middleware' => [' web']],function(){

答案 2 :(得分:0)

删除此文件夹storage/framework/sessions内的所有内容 并确保此文件夹具有写入权限

答案 3 :(得分:0)

文件' /config/session.php'存在于您的项目中?如果没有,请创建它并确保正确设置所有选项。