How To Solve The Page Expired 419 Error In Laravel

  • Many times we faced “The page has expired due to inactivity Please refresh and try again” error in Laravel. This problem is caused by the csrf_token. So, below I have added 2 solutions of this error check and apply as per your requirements.

Read Also : How To Increase Session Lifetime In Laravel

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.

Need to just add @csrf in top of the form.

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

Solution 2

If you are getting an 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 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, Routes in Laravel check below.

Read Also : Laravel Clear Cache Using Artisan Command

I am very appreciate if you like, share and comment.
Thank You For Reading !!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Websolutionstuff

Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API.