DEV Community

Techsolutionstuff
Techsolutionstuff

Posted on • Originally published at techsolutionstuff.com

How To Solve The Page Expired 419 Error In Laravel

In this tutorial I will give you solution of page expired 419 error in Laravel. Many times we faced “The page has expired due to inactivity.

Please refresh and try again”. error in Laravel. This problem is caused by the csrf_token. So, below I have added example of this error check and apply as per your requirments.


Read Also : How To Increase Session Lifetime In Laravel


Example 1 :

If you are getting an error after submitting the form in laravel then you need to add the CSRF field in your form like below.

<form method="POST" action="/test">
    @csrf
    .....
</form>
Enter fullscreen mode Exit fullscreen mode

Example 2 :

If you are getting an error after AJAX call then you need to add a header like below in meta tag.

In your head tag.

<meta name="csrf-token" content="{{ csrf_token() }}">
Enter fullscreen mode Exit fullscreen mode

And after that you need to add below code in your script tag.

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
Enter fullscreen mode Exit fullscreen mode

In some conditions also happen Cache issue, So, we need to clear it.

For clearing Cache, View, Routes in Laravel check below.

Read Also : Laravel Clear Cache Using Artisan Command


You might also like :

Discussion (0)