laravel 5 csrf_token value is Empty

匆匆过客 提交于 2019-12-01 06:42:48
Victor Hugo Avelar

It's because you're not using the web group middleware. Laravel is smart enough to know that if you're not using that group a token is not necessary.

Try moving your route inside the Route::group(['middleware' => 'web'] ... and tell us about it :)

Source: I made the same mistake not too long ago.

I stumbled across this post having spent the afternoon suddenly experiencing "The page has expired due to inactivity. " when I POSTed. When doing a "view source" all tokens were present and correct. It was only that I had included:

  $("#editaddTarget input").each(function () {
                    $(this).val("");

                });

That got fired when I launched a modal. So I learned something today and will not get back the 5 hours it took me to find this newbie clanger!

Thanks to all.

Finally i find solution.

On Fresh Install:

Route::get('foo', function () {
  return csrf_token(); // null
});

Use this:

Route::group(['middleware' => 'web'], function () {
  Route::get('bar', function () {
    return csrf_token(); // works
});

});

Its Working.

ujwal dhakal

Try echo Form::token();? If it doesn't work, try using php artisan generate:key on the console.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!