How to use csrf_token in non-views in Laravel
習慣沉默
習慣沉默 2017-05-16 16:50:07
0
2
517

Excuse me, masters, how can I use csrf_token in Laravel without a view? I wrote a php file in public, and wrote a form in it that needs to be submitted by post, but csrf_token cannot be used. How to solve this problem?

習慣沉默
習慣沉默

reply all(2)
巴扎黑

In blade, you can use {{csrf_token()}} to quickly get the csrf token value

Track into the source code: app('session')->getToken() .

From the above code, it should be inconvenient to use, because your own php file under public does not start laravel core resources through index.php, and the session must not be obtained. Laravel's session is processed and is not PHP native session

滿天的星座

1. Obtain through Session facade

Session::token();

2. Use app to create a session instance to obtain

app('session')->getToken();

3. Get it from blade

{{csrf_token()}}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template