Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

page expired exception in laravel?

This is often seen in Laravel. When a form is submitted, sometimes the application redirects to a page saying:

The page has expired due to inactivity.

Please refresh and try again.

I know that this is a security mechanism in Laravel against CSRF. How can it be prevented from displaying since this may not be appropriate when application is deployed in production server.

like image 695
Birendra Gurung Avatar asked Nov 04 '25 22:11

Birendra Gurung


1 Answers

It's the 419.blade.php template that is being resolved.

If you want to change the message, you can make this file in views/errors/419.blade.php

If you want to capture the exception and perform your own actions against it, you can use the App\Exceptions\Handler.php and specifically capture $e instanceof TokenMismatchException.

Then within that conditional you can choose what action to take.

like image 145
Ohgodwhy Avatar answered Nov 06 '25 20:11

Ohgodwhy