0
0
LaravelDebug / FixBeginner · 3 min read

How to Fix 419 Page Expired Error in Laravel Quickly

The 419 Page Expired error in Laravel happens because the CSRF token is missing or invalid in your form submission. To fix it, ensure you include @csrf in your Blade forms and that your session is properly configured and active.
🔍

Why This Happens

The 419 Page Expired error occurs when Laravel's security system detects a missing or invalid CSRF token in a form submission. Laravel uses CSRF tokens to protect your app from malicious attacks by verifying that the form request is genuine. If the token is missing or expired, Laravel blocks the request and shows this error.

html
<form method="POST" action="/submit">
  <input type="text" name="name">
  <button type="submit">Send</button>
</form>
Output
419 Page Expired error when submitting the form
🔧

The Fix

To fix the 419 error, add the @csrf directive inside your Blade form. This adds a hidden input with a valid CSRF token. Also, make sure your session is working correctly because Laravel stores the token in the session.

blade
<form method="POST" action="/submit">
  @csrf
  <input type="text" name="name">
  <button type="submit">Send</button>
</form>
Output
Form submits successfully without 419 error
🛡️

Prevention

Always include @csrf in your forms to avoid missing tokens. Check that your session driver is properly set in config/session.php and that your app's encryption key is set in .env. Avoid long session lifetimes that can cause token expiration. Use Laravel's built-in form helpers to reduce mistakes.

⚠️

Related Errors

Other errors related to CSRF tokens include:

  • TokenMismatchException: Happens when the token does not match the session token.
  • Session Expired: Occurs if the session times out before form submission.

Fixes usually involve checking session settings and ensuring tokens are included in forms.

Key Takeaways

Always include @csrf in Blade forms to provide a valid CSRF token.
Ensure your session configuration is correct and the session is active.
Check that your app key is set in the .env file for encryption.
Avoid long delays between loading the form and submitting it to prevent token expiration.
Use Laravel's form helpers to reduce manual errors with tokens.