From 703adfcb78a84c18348088cf09f733c12cf4c1a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Thu, 28 Jan 2016 16:00:31 +0100 Subject: [PATCH] FEATURE #1386: catch CSRF token exception --- app/Exceptions/Handler.php | 6 ++++++ resources/lang/en/validation.php | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 53617ef4..9a32465b 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -3,6 +3,7 @@ namespace App\Exceptions; use Exception; +use Illuminate\Session\TokenMismatchException; use Illuminate\Validation\ValidationException; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Database\Eloquent\ModelNotFoundException; @@ -45,6 +46,11 @@ class Handler extends ExceptionHandler */ public function render($request, Exception $e) { + if ($e instanceof TokenMismatchException){ + //redirect to form an example of how I handle mine + return redirect($request->fullUrl())->with('error', trans('validation.csrf')); + } + return parent::render($request, $e); } } diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index b0a1f143..470652e5 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -29,6 +29,7 @@ return [ ], 'boolean' => 'The :attribute field must be true or false.', 'confirmed' => 'The :attribute confirmation does not match.', + 'csrf' => 'Opps! Seems you could not submit form for a longtime. Please try again', 'date' => 'The :attribute is not a valid date.', 'date_format' => 'The :attribute does not match the format :format.', 'different' => 'The :attribute and :other must be different.', @@ -76,7 +77,6 @@ return [ 'timezone' => 'The :attribute must be a valid zone.', 'unique' => 'The :attribute has already been taken.', 'url' => 'The :attribute format is invalid.', - /* |-------------------------------------------------------------------------- | Custom Validation Language Lines @@ -88,12 +88,11 @@ return [ | */ - 'custom' => [ + 'custom' => [ 'attribute-name' => [ 'rule-name' => 'custom-message', ], ], - /* |-------------------------------------------------------------------------- | Custom Validation Attributes @@ -105,6 +104,6 @@ return [ | */ - 'attributes' => [], + 'attributes' => [], ];