Fix handling validation errors

This commit is contained in:
Pig Fang 2018-07-21 17:56:04 +08:00
parent b2a514d3fe
commit 0da5c0ce41

View File

@ -62,7 +62,7 @@ class Handler extends ExceptionHandler
if ($e instanceof ValidationException) {
// Quick fix for returning 422
// @see https://prinzeugen.net/custom-responses-of-laravel-validations/
if ($request->expectsJson()) {
if ($request->expectsJson() || $request->ajax()) {
return response()->json([
'errno' => 1,
'msg' => $e->validator->errors()->first()