How to Fix 419 Page Expired Error in Laravel

The 419 Page Expired error in Laravel almost always means one thing: the CSRF token in your request did not match the one in your session. This guide shows how to find which of the six usual causes is yours โ€” and fix it in minutes.

RH Raja HunainAuthor 24 Nov 2026 8 min read 12 views
On this page
Share

Explanation

You fill in a form, click submit, and instead of a success message you get a plain grey screen:

419 | PAGE EXPIRED

No stack trace, no hint, just a number. It is one of the most common errors beginners meet in Laravel, and it looks far more serious than it is. In almost every case it has a single cause: the CSRF token your request carried did not match the token in your session. This guide walks through the six usual causes in order, from the most common to the rarest.

What the 419 error actually means

First, a useful fact: HTTP 419 is not a standard status code โ€” Laravel invented it for exactly one situation, a CSRF token mismatch. When a form or AJAX request sends a POST, PUT, PATCH or DELETE request, Laravel's VerifyCsrfToken middleware compares the token in the request with the one stored in the session. If the token is missing, does not match, or the session cannot be found, the middleware throws a TokenMismatchException and Laravel answers with a 419.

That explains why the error feels random: the same form can work ten times and fail on the eleventh, because the token is fine and the session changed. When you see a 419, do not start with your routes or controller โ€” ask first: did my request carry a token, and could Laravel read the session it belongs to?

Fix 1: Add @csrf to every form

This is the cause in most cases, and the easiest to check: every HTML form that sends anything other than GET needs a CSRF token, and in Blade one directive adds it:

<form method="POST" action="/posts">
    @csrf
    <input type="text" name="title">
    <button type="submit">Save</button>
</form>

The @csrf directive renders a hidden input named _token holding the session token. Without it, Laravel has nothing to compare and rejects the request. If your form changes the method, keep @csrf next to @method โ€” both are needed:

<form method="POST" action="/posts/1">
    @csrf
    @method('PUT')
    <button type="submit">Update</button>
</form>

In very large forms, put @csrf first inside the <form> tag: PHP's max_input_vars setting (1,000 by default) silently drops fields beyond the limit, so a token placed at the bottom of a form with hundreds of inputs can be cut off before it reaches Laravel.

Fix 2: Send the token with AJAX and fetch requests

JavaScript requests do not get a token automatically โ€” your code has to attach one. If your app posts data with fetch() and the tutorial you followed never mentioned CSRF, this is very likely your cause.

Put the token in a meta tag in your layout's <head>, then read it in JavaScript:

<meta name="csrf-token" content="{{ csrf_token() }}">
const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');

const response = await fetch('/posts', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'X-CSRF-TOKEN': token,
    },
    body: JSON.stringify({ title: 'Hello', body: 'My first post.' }),
});

Axios does this for you on same-origin requests: it reads Laravel's XSRF-TOKEN cookie and sends it back as X-XSRF-TOKEN automatically. With raw fetch() that automation does not exist โ€” the header is your job. Whatever library you use, check in the browser's Network tab that the request actually carries X-CSRF-TOKEN or X-XSRF-TOKEN before looking anywhere else.

Fix 3: Refresh the page when the session has expired

Sometimes the form is perfect and the error still appears โ€” usually after the page sat open a long time. CSRF tokens live in the session, and sessions expire: Laravel's default lifetime is 120 minutes. Open a form, walk away for two hours, submit it, and the stored token is gone โ€” 419.

This is Laravel working as designed, not a bug โ€” the answer is a friendly custom 419 page (see Fix 7). If expired sessions are a daily complaint, extend the lifetime in config/session.php or .env:

SESSION_LIFETIME=480

That gives users eight hours instead of two โ€” but a long session lifetime is a security trade-off, so do not raise it just to hide the error.

When @csrf is present and the token is sent, but the error still appears โ€” especially only in production โ€” the session cookie itself is usually the problem. Two settings in config/session.php, driven by .env, cause most of these cases:

SESSION_DOMAIN=.yourdomain.com
SESSION_SECURE_COOKIE=true

SESSION_DOMAIN must match the domain serving your app. If you changed domains and left an old value behind, the browser never sends the cookie back, Laravel finds no session, and every POST returns 419. Unsure what it should be? Leave it empty (SESSION_DOMAIN=) and Laravel uses the current host.

SESSION_SECURE_COOKIE=true sends the cookie only over HTTPS โ€” set it while serving over plain HTTP and the cookie vanishes, so every POST fails. Flip it to false on HTTP, or better, serve the whole app over HTTPS.

Also check same_site in the same file: the default lax is right for almost every app, while strict drops the session cookie on cross-site POSTs โ€” including legitimate ones from a payment gateway redirect โ€” and those fail with a 419.

Fix 5: Make sure sessions can be stored at all

If the cookie settings are right and the error still happens on every form, Laravel may be unable to save sessions at all โ€” common after a fresh deployment, when the session driver changed or the storage directory lost its permissions.

With the default file driver, storage/framework/sessions must be writable by the web server:

chmod -R 775 storage/framework/sessions

With the database driver, check that the sessions table exists โ€” run php artisan migrate and look for it. A missing table means every request starts with an empty session, and every POST fails. Confirm the active driver with php artisan tinker and config('session.driver'). Fix the storage, and the 419 errors disappear with it.

Fix 6: Exclude routes that should not have CSRF protection

Some routes must accept POST requests from outside your app โ€” Stripe webhooks or PayPal notifications, for example. Those callers have no CSRF token and never will, so exclude exactly those routes instead of disabling CSRF protection globally.

In Laravel 11 and newer, open bootstrap/app.php and list the URIs to exclude:

->withMiddleware(function (Middleware $middleware) {
    $middleware->validateCsrfTokens(except: [
        'stripe/*',
        'paypal/webhook',
    ]);
})

In Laravel 10 and earlier, the same list lives in the VerifyCsrfToken middleware:

class VerifyCsrfToken extends Middleware
{
    protected $except = [
        'stripe/*',
        'paypal/webhook',
    ];
}

Keep the list short: every excluded route accepts unauthenticated POST requests, so list only the exact paths the service calls, and verify the sender another way โ€” a webhook signature, for example โ€” inside the controller.

Fix 7: Show a helpful custom 419 page

Even with everything fixed, a user can still hit a 419 when a session genuinely expires. The default grey screen tells them nothing, so replace it with resources/views/errors/419.blade.php:

<h1>This page has expired</h1>
<p>Your session ended before you submitted the form. Please go back, refresh the page, and try again.</p>
<a href="{{ url()->previous() }}">Go back</a>

Laravel picks up this view automatically on every 419. It fixes nothing by itself, but it turns a dead end into a one-click recovery.

Quick diagnosis: match your symptom to the fix

What you see Most likely cause Fix
Every form fails, first try Missing @csrf in the form Fix 1
Forms work, AJAX calls fail No token header on the request Fix 2
Fails only after the page sat open Session expired Fix 3 + Fix 7
Works locally, fails in production SESSION_DOMAIN or SESSION_SECURE_COOKIE wrong Fix 4
Every POST fails, even with @csrf Sessions cannot be stored Fix 5
Only a webhook or external POST fails Route needs CSRF exclusion Fix 6

Frequently asked questions

Is 419 a Laravel-only error? Yes, in practice โ€” it is not a standard HTTP code, Laravel created it for CSRF token mismatches, so you only meet it in Laravel apps.

Do API routes need CSRF tokens? No โ€” routes in routes/api.php never pass through the CSRF middleware. If your API returns 419, the request is probably hitting a web route by mistake. Sanctum tokens, not CSRF, are the right protection for APIs.

Why does the error appear only sometimes? A missing token fails every time, but an expiring session, a cookie dropped on one subdomain, or a cached page holding an old token fails only when those conditions line up โ€” which looks random until you know what to check.

Should I disable CSRF protection to stop the error? No โ€” disabling it removes the check that stops other websites submitting forms as your users. Fix the token or the session instead.

Conclusion

The 419 error looks cryptic, but it always asks the same two questions: did the request carry a CSRF token, and could Laravel find the session it belongs to? Work through the fixes in order โ€” @csrf in forms, the token header on AJAX requests, session and cookie settings, session storage, and exclusion only for webhook routes that truly need it. One of those six is almost always the answer, and the fix is usually a single line.

Add a custom 419 page while you are there, so the next expired session shows a helpful message instead of a grey screen.

#Laravel #Laravel13 #CSRF #Debugging #WebDevelopment #ErrorFix

Was this helpful? 0 likes Login to like & bookmark
RH

Written by

Raja Hunain

Full Stack Developer at Raja Dev Solutions โ€” writes about real development work, the errors he faced and exactly how he fixed them, plus practical Laravel, PHP, JavaScript and MySQL tutorials.

More about the author

Comments (0)

No comments yet. Be the first to comment.

Leave a comment

Comments are moderated and appear after approval.

Keep reading

Related Errors & Articles

Error & Fix PHP Development 22 Nov 2026 ยท 2 min read

How to Fix "Headers Already Sent" Error in PHP

PHP says "Cannot modify header information - headers already sent" when output reaches the browser before your header() call. Here is how to read the message, find the exact line that sent output, and fix it for good.