How To Solve The Page Expired 419 Error In Laravel

Websolutionstuff | Jun-28-2020 | Categories : Laravel

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.

Solution 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>

 

 

Solution 2:

 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:

Recommended Post
Featured Post
Autocomplete Search using Bootstrap Typeahead JS
Autocomplete Search using Boot...

In this example we will see autocomplete search using bootstrap typeahead js.Typeahead search is a method for progr...

Read More

Jun-09-2021

Helper Function Example in Laravel 8
Helper Function Example in Lar...

Hello All, In this post we will see helper function example in laravel, Laravel provide in-buit global "hel...

Read More

Jun-22-2021

How To Get Children Element In jQuery
How To Get Children Element In...

In this article, we will see how to get the children of this selector in jquery. You can use the find() method...

Read More

Jul-13-2022

Carbon Add Days To Date In Laravel
Carbon Add Days To Date In Lar...

In this article, we will see carbon add days to date in laravel. Carbon provides the addDay() and addDays() functions to...

Read More

Dec-03-2020