In this tutorial, I'll provide you with a solution to the "419 Page Expired" error in Laravel. This error, often displayed as "The page has expired due to inactivity. Please refresh and try again," is typically caused by the csrf_token.
To help you resolve this issue, I've included an example for diagnosing and addressing it based on your specific requirements.
Discover practical examples and step-by-step guidance to overcome the common "419 Page Expired" error in Laravel 8, Laravel 9, and Laravel 10.
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>
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() }}">
And after that you need to add below code in your script tag.
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
In some conditions also happen Cache issue, So, we need to clear it.
For clearing Cache, View, Routes in Laravel check below.
You may also like: