In this example, I will provide a solution of 419 pages expired laravel. We will discuss how to solve the problem 419 pages expired in laravel.

You must pass a csrf token when you use the Post, Delete, Put and Patch method in Laravel. You can not use csfr token then you get laravel 419 page expired. we will show 419 pages expired laravel ajax.


Solution 1

When you are getting 419 page expired error after submitting the form in laravel then you required to add the CSRF field in your form like below.

<form method="POST" action="/test">
    @csrf
    .....
</form>


Solution 2

When you are getting an page expired 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 required 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.