Laravel 5.5 - The page has expired due to inactivity. Please refresh and try again

1

I'm trying to upload images to a project, after uploading 2 or 3 images I get the error

  

The page has expired due to inactivity. Please refresh and try again.

It takes me out of the session and when I try to log in, I get the same error again, in version 5.4 it worked fine, was there a change?

I see this error in the browser console: Failed to load resource: the server responded to a status of 419 (unknown status)

My create function is:

public function create(CreateMessageRequest $request){

      $image = $request->file('image');

      $user = $request->user();

      $message = Message::create([

        'image' => $image->store('messages','public'),

        'content' => $request->input('message'),

        'user_id' => $user->id,

      ]);

The form has:

<div class="row">
<form class="" action="/message/create" method="post" enctype="multipart/form-data">
  {{csrf_field()}}
  <div class="form-group">
    <input class="form-control" type="text" name="message" value="" placeholder="Que Estas Pensando?">
  </div>
  <input type="file" class="form-control-file" name="image">
</form>
    
asked by MarianoV 02.09.2017 в 03:43
source

2 answers

0
In version 5.5 of Laravel "TokenMismatch" generates an exception or more "friendly" message along with code 419, while in previous versions it generated an error 500 that according to those who make Laravel, was less coherent and did not reflect the reality of a Token problem.

I was reviewing the Laravel 5.5 code and comparing it with Laravel 5.4 and apparently neither the generation of the Token (in the session manager) nor the verification of it (Middleware VerifyCrsfToken) changed.

I have not had your problem, but the provisional solution they give in some sites is to clean the browser cache (cookies and etc.) , but it would not seem ideal, at least for production .

    
answered by 02.09.2017 в 05:46
0

Update with composer update the latest version of 5.5 and a more friendly message will appear and redirect you to the loqueo system

however check the Handler file located in app / Exceptions and you should have a method like this, if not add it

/**
     * Convert an authentication exception into an unauthenticated response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Illuminate\Auth\AuthenticationException  $exception
     * @return \Illuminate\Http\Response
     */
    protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        return redirect()->guest(route('login'));
    }

you should have the version

$ php artisan --version

Laravel Framework 5.5.17 that solves this error

    
answered by 19.10.2017 в 15:00