示例#1
0
 protected function displayErrors(MessageBag $errors)
 {
     foreach ($errors->all() as $error) {
         $this->error($error);
     }
     $this->info('Please try again');
 }
 /**
  * @return string
  */
 public function getHtmlMessage()
 {
     if (!$this->htmlMessage) {
         $this->htmlMessage = sprintf("<ul class='validation-msgs'><li>%s</li></ul>", join('</li><li>', $this->bag->all()));
     }
     return $this->htmlMessage;
 }
示例#3
0
 /**
  * Validate model.
  *
  * @return bool
  */
 public function validate()
 {
     $this->validationDirty = true;
     if (false === $this->fireValidationEvent('validating')) {
         $this->errors = $this->errors ?? new MessageBag();
         $this->errors->add('::validating', 'Pre-validation event returned false.');
         return false;
     }
     $validator = $this->getValidationFactory()->make($this->getAttributes(), $this->getValidationRules(), $this->getValidationMessages(), $this->getValidationCustomAttributes());
     if ($fails = $validator->fails()) {
         $this->errors = $validator->getMessageBag();
     }
     if (false === $this->fireValidationEvent('validated')) {
         $this->errors = $this->errors ?? new MessageBag();
         $this->errors->add('::validated', 'Post-validation event returned false.');
         return false;
     }
     return !$fails;
 }
 /**
  * Handle a failed validation attempt.
  *
  * @param MessageBag $errors
  * @return mixed
  */
 protected function failedNestedValidation(MessageBag $errors)
 {
     throw new HttpResponseException($this->response($errors->toArray()));
 }
 /**
  * Get the string representation of the exception.
  *
  * @return string
  */
 public function __toString()
 {
     $lines = explode("\n", parent::__toString());
     return array_shift($lines) . " \nValidation errors:\n" . implode($this->errors->all(), "\n") . "\n" . implode($lines, "\n");
 }
示例#6
0
 private function getListFromSystemErrorArray(MessageBag $systemErrors = null)
 {
     $list = '';
     if ($systemErrors) {
         foreach ($systemErrors->all() as $key => $value) {
             $list .= '<li>' . $value . '</li>';
         }
     }
     return $list;
 }
示例#7
0
 /**
  * Create a new validation exception instance.
  * @param MessageBag $errors
  */
 public function __construct(MessageBag $errors)
 {
     $this->errors = $errors->toArray();
 }
 /**
  * @return bool
  */
 public function isEmpty()
 {
     return $this->messages->isEmpty();
 }
 /**
  * @param MessageBag $messageBag
  * @return mixed
  */
 public function errorWrongArgsValidator(MessageBag $messageBag)
 {
     return $this->errorResponse(['code' => Error::CODE_VALIDATION_FAILED, 'title' => 'Input validation failed', 'details' => $messageBag->toArray()], SymfonyResponse::HTTP_UNPROCESSABLE_ENTITY);
 }
 /**
  * ValidationJsonApiResponse constructor.
  * @param MessageBag $errors
  */
 public function __construct(MessageBag $errors)
 {
     $this->prepare('errors', $this->normalizeErrors($errors->all()));
 }
示例#11
0
 /**
  * Create a new validation exception instance.
  * @param MessageBag $errors
  * @param string $message
  * @param \Exception $previous
  * @param array $headers
  * @param int $code
  */
 public function __construct(MessageBag $errors, $message = 'There was an issue with the validation of provided entity', \Exception $previous = null, array $headers = [], $code = 0)
 {
     $this->errors = $errors->toArray();
     parent::__construct(Response::HTTP_UNPROCESSABLE_ENTITY, $message, $previous, $headers, $code);
 }