search

Home  >  Q&A  >  body text

CSRF token requested per post does not match Laravel 9

<p>I receive a Csrf token mismatch error for <strong>every post request</strong> I make in my project. I'm using ajax in some places and normal form submission in others. However the error is constant. </p> <p>I have tried a few things as suggested on this site, such as </p> <ol> <li>Set<code>SESSION_SECURE_COOKIE=false</code>. </li> <li>Add <code>@csrf</code></code></li> inside <code><form></form> <li>Add <code><meta name="csrf-token" content="{{ csrf_token() }}" /></code> and <code>$.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content');}});</ code>Before the ajax call. </li> <li>Run<code>php artisan config:clear</code> <code>php artisan route:clear</code> <code>composer dump-autoload</code>. </li> <li>Run the project on different browsers. </li> </ol> <p>The error is the same throughout. The app works very well. What am I missing? </p>
P粉521697419P粉521697419517 days ago575

reply all(1)I'll reply

  • P粉883223328

    P粉8832233282023-08-26 16:44:20

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

    After that run php artisan config:cache.

    reply
    0
  • Cancelreply