Why Your Laravel Form Returns 419 Page Expired (and the One-Line Fix You're Missing)
You submit a form in Laravel, and instead of a success message you get a grey screen: 419 | PAGE EXPIRED. No stack trace, no hint. Just a number. Here is the good news: the 419 error has one cause, and one cause only. L
You submit a form in Laravel, and instead of a success message you get a grey screen: 419 | PAGE EXPIRED. No stack trace, no hint. Just a number.
Here is the good news: the 419 error has one cause, and one cause only. Laravel's CSRF middleware compared the token in your request with the token in your session, and they did not match — or the session was not there at all. Fix the token or the session, and the error is gone.
The fix that solves most cases
Every form that sends POST, PUT, PATCH or DELETE needs a CSRF token. In Blade, one directive adds it:
<form method="POST" action="/posts">
@csrf
<input type="text" name="title">
<button type="submit">Save</button>
</form>
@csrf renders a hidden _token input. Forget it, and Laravel rejects the request with a 419 before your controller ever runs. If you are debugging a 419, this is the first thing to check — and it is the answer more often than any other.
The case everyone misses: JavaScript requests
Forms are only half the story. A fetch() call does not get a token automatically. If your form works but your JavaScript POST fails with 419, your code never sent the token.
Put the token in a meta tag in your layout:
<meta name="csrf-token" content="{{ csrf_token() }}">
Then attach it to the request:
const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
await fetch('/posts', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': token,
},
body: JSON.stringify({ title: 'Hello' }),
});
Axios users get this for free on same-origin requests — it reads Laravel's XSRF-TOKEN cookie and sends it back as X-XSRF-TOKEN. With raw fetch(), the header is your job. Open the Network tab and confirm the request actually carries X-CSRF-TOKEN before you look anywhere else.
When it only fails in production
This one confuses people the most: everything works on your laptop, every form fails on the live server. Two settings in config/session.php cause it:
-
SESSION_DOMAINmust match the domain serving the app. Change domains and leave an old value behind, and the browser never sends the cookie back — Laravel finds no session, and every POST returns 419. -
SESSION_SECURE_COOKIE=truesends the cookie only over HTTPS. Set it while serving over plain HTTP and the cookie vanishes.
Also check that sessions can be stored at all. With the default file driver, storage/framework/sessions must be writable by the web server. A fresh deployment with wrong permissions fails every single POST.
The full checklist
If you want every cause in one place — expired sessions, webhook routes that need CSRF exclusion, and a custom 419 page so your users see a helpful message instead of a grey screen — I wrote the complete step-by-step guide here: https://rajadevsolutions.online/errors/how-to-fix-419-page-expired-error-in-laravel
The short version: the 419 error always asks the same two questions. Did the request carry a token? Could Laravel find the session it belongs to? Answer those, and the fix is usually a single line.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.