VerifyCsrfToken in Laravel framework solves the error,
Preface
This article describes VerifyCsrfToken errors in the Laravel framework for your reference. I will not talk about them here. Let's take a look at the details.
Error Message
The following error occurs when submitting data using form post.
TokenMismatchException in VerifyCsrfToken.php line 67:in VerifyCsrfToken.php line 67at VerifyCsrfToken->handle(object(Request), object(Closure))
Post Data submission Error
Cause
Laravel recommends that the Middleware of VerifyCsrfToken be registered globally. It automatically verifies whether _ csrf token is valid for all Post, Put, and Delete requests.
Solution
Method 1. Add the following hidden domain code to the form.
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
Method 2: Add csrf_field to form
(Consistent with the above solution functions)
{!! csrf_field() !!}
Method 3. comment out the Kernel. php code
Open app \ Http \ Kernel. php and comment out the following code in the file.
\App\Http\Middleware\VerifyCsrfToken::class
Method 4. Modify the handle () method
Open \ app \ Http \ Middleware \ VerifyCsrfToken. php and add or modify handle () as follows:
Public function handle ($ request, \ Closure $ next) {// use CSRF // return parent: handle ($ request, $ next ); // disable CSRF return $ next ($ request );}
Supplement csrf Introduction
Csrf illustration
References
1. Laravel 5.3 document-CSRF attack principles and protection
2. Laravel 5.3 documentation-HTTP layer CSRF Protection
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.