Laravel 5.5 - The page has expired due to inactivity - fixed

September 16, 2017 | Category : Laravel 5.5 Laravel 5 Laravel PHP

Yesterday, i was working on new laravel 5.5 blog and i was making quick contact us form and i didn't use Form facade for that. i just simply use html input form element. But when i create post route and then submit my form i got following error:


The page has expired due to inactivity.

Please refresh and try again.


I was thing i haven't seen this error on my laravel 5.4 or 5 application. Then i search on google and found it is a "TokenMismatchException" error that was on laravel 5 old version. We can prevent this error using csrf_field() field. Laravel gives security on token based so you must have to pass csrf_field token on post submit method So, let's use following token by as bellow:

Add csrf token hidden field on Form:

{!! csrf_field() !!}

OR

<input type="hidden" name="_token" value="{{ csrf_token() }}">

You can add above way to csrf_token in your form. So don't get again same error.

I hope you found your best solution...