In this article, we'll learn how to resolve the "419 page expired" error in Laravel. You might have encountered the message "The page has expired due to inactivity. Please refresh and try again" in your Laravel applications. This issue is related to the csrf_token, and we'll explore two solutions to fix it.
Let's dive into solving the 419 error in Laravel, including how to handle it in Laravel AJAX requests.
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 an AJAX call then you need to add a header like the below in the meta tag.
In your head tag add the below line code.
<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, and Routes in Laravel check below.
You might also like:
In this article, we will see how to remove/delete files from public folders. We will give you a demo of how to remo...
Sep-14-2020
In this article, we see how to integrate razorpay payment gateway in laravel 9. As you all know if you are developi...
Apr-11-2022
In this article, we will see how to remove a specific item from an array in javascript. We will use the indexOf() m...
Nov-03-2022
In this article, we will show you how to create a dynamic bar chart in laravel. charts are used to represent data i...
Jul-01-2020