Laravel – Fix 419 Page Expired with config:cache

By

in

,

Posted

Tags:

Updated

I’m working on a project that uses Laravel and sessions for login and other forms. I’ve encountered an issue where I would encounter a 419 Page Expired error when running my project on a local development environment. The solution ended up being the need to manually cache the config with:

php artisan config:cache

Whenever you change the config, run this again. I’m not too sure why this is happening, perhaps the config is unaccessible if it’s not working, I think this is an issue when you run a php artisan optimize:clear or similar.

Some things I noticed specific to my issue:

  • The CSRF token is included in the document body in a tag
  • BUT inspecting the request response shows that there is no session cookie being sent in the header (the cookie name is specific to your project)
    • Nor is any other Set-Cookie header being sent, so it seems cookies are broken in these cases
  • After fixing this issue, trying to reproduce it by clearing the caches seems to result in a redirect.

Some other alternative solutions I’ve tried from my Googling:
php – 419 Page Expired In Laravel Even after adding CSRF token – Stack Overflow

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *