response( $this->formatErrors($validator) )); } /** * Format the errors from the given Validator instance. * * @param \Illuminate\Contracts\Validation\Validator $validator * @return array */ protected function formatErrors(Validator $validator) { return $validator->getMessageBag()->toArray(); } /** * Get the proper failed validation response for the request. * * @param array $errors * @return \Symfony\Component\HttpFoundation\Response */ public function response(array $errors) { if ($this->expectsJson()) { return new JsonResponse($errors, 422); } return $this->redirector->to($this->getRedirectUrl()) ->withInput($this->except($this->dontFlash)) ->withErrors($errors, $this->errorBag); } }