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 Avoid TokenMismatchException On Logout
How To Avoid TokenMismatchExce...

Many times we faced a Tokenmismatch error in laravel. This error occurs If you stay too long time on one form...

Read More

Jun-29-2020

Laravel 8 Socialite Login with Google Account
Laravel 8 Socialite Login with...

In this article, we will see laravel 8 socialite login with a google account. This post gives you an example of a larave...

Read More

Dec-01-2020

Laravel 9 Livewire Dependent Dropdown
Laravel 9 Livewire Dependent D...

In this article, we will see the laravel 9 livewire dependent dropdown. Here, we will learn how to create a dependent dr...

Read More

Nov-29-2022

How To Create User Roles And Permissions In Laravel 10
How To Create User Roles And P...

In this article, we will see how to create user roles and permissions in laravel 10. Here, we will learn about roles and...

Read More

Apr-03-2023