Created
July 14, 2018 20:02
-
-
Save manuelgeek/135dde98626d740a1fd5f12bff69a20b to your computer and use it in GitHub Desktop.
Token Mismach Exception Handling in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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