TokenMismatchException in VerifyCsrfToken.php Line 67

I was about to start pulling out my hair!

Please check your session cookie domain in session.php config. There is a domain option that has to match your environment and it's good practice to have this configurable with you .env file for development.

'domain' => env('COOKIE_DOMAIN', 'some-sensible-default.com'),

I'm assuming you added $this->middleware('auth'); inside the constructor of your controller to get the authentication working. In your login/register forms, if you are using {!! Form::someElement !!}, add the following line at the top as well:

{!! csrf_field() !!}

Or if you are using input tags inside your forms, just add the following line after <form> tag:

<input type="hidden" name="_token" value="{{ csrf_token() }}">

Hope this helps.


I had a similar issue and it was an easy fix.

Add this in your HTML meta tag area :

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

Then under your JQuery reference, add this code :

<script type="text/javascript">
      $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
      });
  </script>

If you are using the HTML form submit (not AJAX) then you need to put :

{{ csrf_field() }} 

inside your form tags.

Tags:

Laravel 5.2