Security Laravel 8 Laravel 9 Laravel 10 Laravel 11 Laravel 12

CSRF Token Mismatch Error in Laravel - Complete Fix

The CSRF token mismatch error occurs when the token submitted with a request doesn't match the one stored in the session.

The Error

Error Message
CSRF token mismatch

Common Causes

  1. 1 Token expired due to session timeout
  2. 2 Multiple browser tabs with different tokens
  3. 3 Token not sent with AJAX request
  4. 4 Session driver misconfiguration
  5. 5 Load balancer not sharing sessions

Solutions

1

Ensure CSRF token is in all forms

Blade
<form method="POST">
    @csrf
    <!-- or -->
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
2

Configure Axios to send CSRF token

JavaScript
axios.defaults.headers.common['X-CSRF-TOKEN'] = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
3

Check session configuration

PHP
// config/session.php
'lifetime' => 120,
'expire_on_close' => false,
'same_site' => 'lax',

Need Help With Your Laravel Project?

I specialize in building custom Laravel applications, process automation, and SaaS development. Whether you need to eliminate repetitive tasks or build something from scratch, let's discuss your project.

Hafiz Riaz

About Hafiz

Senior Full Stack Developer. I build production software with Laravel, Filament, Vue, and AI integrations, and write about the real decisions behind shipping it.

Get in touch →

Related Errors