VerifyCsrfToken.php第46行中的Laravel 5 TokenMismatchException [英] Laravel 5 TokenMismatchException in VerifyCsrfToken.php line 46

查看:81
本文介绍了VerifyCsrfToken.php第46行中的Laravel 5 TokenMismatchException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按登录"按钮后,即使是public/auth/login,我也会收到此错误

i get this error even for public/auth/login after pushing the Login button

我只是尝试输出Session :: flash(),但出现此错误消息:

Hi i'm simply trying to output a Session::flash() but I get this error message:

TokenMismatchException in VerifyCsrfToken.php line 46

这是代码:

public function update($id, Requests\EditPostRequest $request)
{

    $post = Post::findOrFail($id);
    $post->update($request->all());
    return redirect(route('news.edit', $id))->with('success', 'Operation successful !');
}

这是我的看法:

  @if(Session::has('success'))
   <div class="alert alert-success">

    {{ Session::get('success') }}
   </div>
  @endif

我真的需要解决这个问题:/

I really need to fix that :/

推荐答案

它似乎与在本地/开发环境和生产环境中使用相同的密钥有关.

It appears to be related to using the same key in both your local/dev environment and production one.

但是,由于会话应该独立于环境,因此我不确定您将如何发生冲突,但是我早些时候在做一些本地开发.开发人员一切正常,将项目推送到另一台PC上,然后我遇到了TokenMismatchException.

I'm not sure how you'd get collisions, though, given that the sessions should be independent of environment, but I was doing some local development earlier. Everything was working fine in dev, pushed my project to my other PC and than I hit the TokenMismatchException.

我在.env文件中戳了一下,果然,两个环境之间的键是相同的.在我的生产环境中更改密钥和TokenMismatchException立即消失了.

I had a poke around my .env file and sure enough, the keys were the same between my two environments. Changing the key in my prod environment and the TokenMismatchException went away straight away.

只要看看您设置的令牌,如果它们相同,就可以使用 php artisan key:generate 更改生产密钥,希望对您有用,请告诉我它是否无效

Just look at your token which get set if they are the same change the production key with php artisan key:generate , hope for you this will work, just let me know if it don't.

这篇关于VerifyCsrfToken.php第46行中的Laravel 5 TokenMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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