From 96e2d74ae3b91fc093842ad819c4eda88aedb006 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 24 May 2019 00:46:30 -0700 Subject: [PATCH] Handle JSON validation errors like 5.4 --- app/Exceptions/Handler.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index b232b8956..3e3500501 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -117,4 +117,16 @@ class Handler extends ExceptionHandler return redirect()->guest('login'); } + + /** + * Convert a validation exception into a JSON response. + * + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Validation\ValidationException $exception + * @return \Illuminate\Http\JsonResponse + */ + protected function invalidJson($request, ValidationException $exception) + { + return response()->json($exception->errors(), $exception->status); + } }