Correctly set headers for Laravel 5 CSRF Token

浪子不回头ぞ 提交于 2019-12-04 11:48:27

This is due to encryption of the csrf token. Laravel expect the token to be encrypted.

It tries to decrypt the the plain token you provide and it fails.

Before you can use the token in the header you have to encrypt it.

$encrypter = app('Illuminate\Encryption\Encrypter');
$encrypted_token = $encrypter->encrypt(csrf_token());

That did the trick for me.

Alex

For Laravel 5, no need to add CSRF token to Angular http headers.

Laravel 5 with Angular do this automatically for you.

http://laravel.com/docs/5.1/routing#csrf-x-xsrf-token

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