What is the best way to handle expired tokens in laravel 5.
I mean I have a page and it has some links which perform ajax requests. They work fine when the page is
Best way to handle this Exception is with App\Exceptions\Handler.php.
public function render($request, Exception $e) {
if ($e instanceof \Illuminate\Session\TokenMismatchException) {
return Redirect::back()->withErrors(['session' => 'Désolé, votre session semble avoir expiré. Veuillez réessayer.']);
}
return parent::render($request, $e);
}
and where ever you wanna show this message (in all your pages that contains csrf_token), add this piece:
@if(count($errors)>0)
@foreach($errors->all() as $error)
- {{$error}}
@endforeach
@endif