Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save manuelgeek/135dde98626d740a1fd5f12bff69a20b to your computer and use it in GitHub Desktop.
Save manuelgeek/135dde98626d740a1fd5f12bff69a20b to your computer and use it in GitHub Desktop.
Token Mismach Exception Handling in Laravel
Replace your app\Exceptions\Handler.php render() function with this
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
if ($exception instanceof \Illuminate\Session\TokenMismatchException)
{
return redirect()
->back()
->withInput($request->except('password'))
->with([
'message' => 'Validation Token was expired. Please try again',
'message-type' => 'danger']);
}
return parent::render($request, $exception);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment