add validation to exception handler
This commit is contained in:
parent
df5b100521
commit
3310063b59
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Auth\AuthenticationException;
|
use Illuminate\Auth\AuthenticationException;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
|
@ -43,7 +44,25 @@ public function render($request, Exception $exception)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an authentication exception into an unauthenticated response.
|
* Convert a validation exception into a response.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param Illuminate\Validation\ValidationException $exception
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
protected function invalid($request, ValidationException $exception)
|
||||||
|
{
|
||||||
|
$errors = $exception->validator->errors()->messages();
|
||||||
|
|
||||||
|
return $request->expectsJson()
|
||||||
|
? response()->json(['message' => $exception->getMessage(), 'errors' => $errors])
|
||||||
|
: redirect()->back()->withInput()->withErrors(
|
||||||
|
$errors, $exception->errorBag
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert an authentication exception into a response.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \Illuminate\Auth\AuthenticationException $exception
|
* @param \Illuminate\Auth\AuthenticationException $exception
|
||||||
|
|
Loading…
Reference in New Issue