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
How to Set Auto Database BackUp using Cron Scheduler In Laravel
How to Set Auto Database BackU...

In this article, we will see how to set auto database backup using the cron scheduler in laravel. here we will set ...

Read More

Feb-18-2021

Laravel 10: New Features And Release Date
Laravel 10: New Features And R...

In our ever-changing digital landscape, staying ahead of the competition is essential. And that's precisely what we&...

Read More

Jan-11-2023

Laravel 8 Socialite Login with Facebook Account
Laravel 8 Socialite Login with...

In this tutorial, we will learn laravel 8 socialite login with facebook account, as you all know currently many websites...

Read More

Mar-08-2021

How To Create Middleware For XSS Protection In Laravel 8
How To Create Middleware For X...

In this tutorial we will see how to create middleware for xss protection in laravel 8. Cross-site scripting is...

Read More

Dec-22-2021