Search code examples
phplaravelcsrflaravel-9

CSRF token mismatch for every post request Laravel 9


I am getting Csrf token mismatch error on every post request I am making in the project. I am using ajax at some places and normal form submission at other places. However the error is constant.

I have tried several things as suggested on this site like

  1. Setting SESSION_SECURE_COOKIE=false.
  2. Adding @csrf inside <form></form>
  3. Adding <meta name="csrf-token" content="{{ csrf_token() }}" /> and $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content');}}); before ajax call.
  4. Running php artisan config:clear php artisan route:clear composer dump-autoload.
  5. Running project on different browsers.

The error is same throughout. The application was working absolutely fine. What is the thing I am missing?


Solution

  • In your config/session.php file, try setting same_site to lax,null.

    After that run php artisan config:cache.