session () - flush () deletes the {!! csrf_field (); !!}

0

When I make a disconnection command to the function: With the aim of deleting all the sessions that user has been creating.

 public function Desconectarse(Request $request) {

         session()->flush();

         return view('index');
     }

And when I put the username and password in the index, it gives an error:

TokenMismatchException in VerifyCsrfToken.php line 53:
    
asked by EduBw 30.11.2017 в 11:29
source

2 answers

0

The token of csrf is saved in session so it is destroyed when using flush and therefore it is no longer available in that request.

In your case I see that it is intended to disconnect, in this case you should apply a redirection instead of returning the view, thus regenerating the token.

That is:

public function Desconectarse(Request $request) {

     session()->flush();
     // redireccion a la ruta deseada
     return redirect('user/login');
    // o utiliza el alias de la ruta 
    return redirect()->route('login');
 }
    
answered by 30.11.2017 в 12:22
-1

Try putting this in the form if you have it out

{{ csrf_field() }}

If it is not this, put the code of the view also

    
answered by 30.11.2017 в 11:32