1

I am using laravel 5.5 when ever i send data in post request to my controller . It always show the following message The page has expired due to inactivity.

Please refresh and try again. my view code is :

@extends('layouts.app')
@section('content')


    <!DOCTYPE html>
    <html>
    <head>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <title></title>
    </head>
    <body>
    <div class="span3 well">
          <legend>Create Your New Task!</legend>
          <div class="form-group">
            <div class="col-md-4">  
             <form accept-charset="UTF-8" action="/add-task" class="form-horizontal" method="post">
            <input class="form-control"   name="name" placeholder="Task Name" type="text"> 
            <input class="form-control"  name="assignedto" placeholder="Assigned To" type="text">
            <input class="form-control"  name="deadline" placeholder="DeadLine" type="text"> 
            <button class="btn btn-warning" type="submit">Add Task</button>
            {{csrf_field()}}
        </form>
        </div>
    </div>
    </div>
    </body>

    </html>

    @endsection()

and my controller is :

<?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\DB;
    use App\task;

    class AddTask extends Controller
    {
        public function insertTask(Request $req)
        {
            $name=new task();
            $name->name=$req['name'];
            $name->assigned_to=$req['assignedto'];
            $name->deadline=$req['deadline'];

            $name->save();

        }
    }

i doen't know what is the solution

Mohammad Arshad
  • 78
  • 1
  • 2
  • 10
  • Would it be a possible solution if you use the header for autoreload after some seconds? ` e.g.: ` You can also refresh the page with JS `location.reload();` Out of the box i cant tell you why you get this error, but its possible that the csrf token reached the end of his "lifecycle". Every generated token is valid for a short time. There should be a setting in your laravel project where you can incrase the default lifetime of the csrf token. – Spears Sep 20 '17 at 10:42
  • 2
    possible duplicate of https://stackoverflow.com/questions/46141705/the-page-has-expired-due-to-inactivity-laravel-5-5 – Basheer Kharoti Sep 20 '17 at 10:49

4 Answers4

4

I had the same problem using localhost:8000 Try below steps
1.Try on clean browser. It seems that the problem is with cookies from development with previous Laravel versions, on the same url.
2.Try to add {{ csrf_field() }} below opening form tag

<form action="/add-task" method="POST">
  {{ csrf_field() }}

3.and remove the accept-charset="UTF-8"

further reading Similiar Post 1 and Similiar Post2
additional link about laravel 5.5 errors Larave 5.5: default error views and costomizing them

Muhammed Anas U
  • 305
  • 1
  • 4
  • 15
1

Pay attention on php.ini mbstring.func_overload parameter.

It has to be set to 0. And mbstring.internal_encoding set to UTF-8. In my case that was a problem.

SAYE
  • 1,247
  • 2
  • 20
  • 47
1

Had to put <input type="hidden" name="_token" value="{{ csrf_token() }}"> or use @csrf in Laravel 5.6 inside form. {{csrf_token()}} otherwise would be printed in html page

Augustas
  • 1,167
  • 21
  • 31
0

had the same problem but /storage/framework/sessions folder was missing. Created the folder and that fixed it after a refresh.