Issue Reason:
In Laravel when we submit any form or try to run any Ajax request then we must
need to add csrf_token() if we do not add this security token in our requests then
laravel throws the security error
Form Submission
Add this hidden input security _token field see below.
Add a request in an array that you want to bypass without any security check.
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Ajax Request
On ajax post or get requests add a header before running ajax request. See below
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
Disable TokenMismatchException using $except array :
We can disable token check/verifying in laravel but it is not recommanded at all.
Please go to the file
/app/Http/Middleware/VerifyCsrfToken.php
here you will find an except array see below
protected $except = [
'/',
];
No comments:
Post a Comment