2

My laravel version was 5.5, and didn't have any errors in my application.
When I upgraded my laravel version to 5.6, the laravel TokenMisMatchException is occurring. I have set csrf in meta, ajaxSetup and html form.
I tried find solution on stackoverflow but I find just ajaxSetup.

$.ajaxSetup({
  headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  }
});  

but I set this now

Cœur
  • 37,241
  • 25
  • 195
  • 267
Hasan Teymoori
  • 192
  • 1
  • 15
  • try a few solutions from https://stackoverflow.com/questions/28875788/laravel-5-auth-post-submit-tokenmismatchexception-in-verifycsrftoken-php-line – Matt Jameson Oct 25 '18 at 16:35

2 Answers2

0

You are also need add meta tag with content.

<meta name="csrf-token" content="{{ csrf_token() }}" />

this works with this.

Ali Özen
  • 1,525
  • 2
  • 14
  • 29
  • oops, sorry. did you have _token parameter in your ajax data? If you didn't have one. add "_token": "{{ csrf_token() }}", – Ali Özen May 14 '18 at 06:55
0
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="js/config.js"></script> // Do your $.ajaxSetup in this file 
<script src="js/app.js"></script>

$(function () {
    $.ajaxSetup({
        headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') }
    });
});