Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

After that run php artisan config:cache.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading