Пример #1
0
 /**
  * Returns errors from the validator. This will return only messages
  * if the request is from ajax.
  *
  * @return array|\Illuminate\Support\MessageBag
  */
 public function getErrors()
 {
     if (Request::ajax()) {
         return $this->errors->getMessages();
     } else {
         return $this->errors;
     }
 }
Пример #2
0
 /**
  * Format the validation errors.
  *
  * @param \Illuminate\Support\MessageBag $errors
  *
  * @return mixed
  */
 protected function formatErrors($errors)
 {
     $output = [];
     foreach ($errors->getMessages() as $field => $message) {
         $output[] = ['code' => 'validation_fails', 'field' => $field, 'message' => isset($message[0]) ? $message[0] : ''];
     }
     return $output;
 }
Пример #3
0
 public function testFirstReturnsSingleMessage()
 {
     $container = new MessageBag();
     $container->setFormat(':message');
     $container->add('foo', 'bar');
     $container->add('foo', 'baz');
     $messages = $container->getMessages();
     $this->assertEquals('bar', $container->first('foo'));
 }
Пример #4
0
 /**
  * Write all alerts to session flash
  */
 public function setFlash()
 {
     $flash = array();
     foreach ($this->bag->getMessages() as $type => $messages) {
         foreach ($messages as $message) {
             $flash[$type][] = $message;
         }
     }
     $this->session->flash(self::SESSION_KEY, $flash);
 }
 /**
  * get all messages from message bag
  * 
  * @param boolean $raw
  * @return mixed
  */
 public function getErrors($raw = false)
 {
     if ($this->errors === null) {
         $this->errors = new MessageBag();
     }
     if ($raw) {
         return $this->errors;
     }
     return $this->errors->getMessages();
 }
Пример #6
0
 public function validate($attributes = [])
 {
     /* @var $this Model */
     if (!method_exists($this, 'rules')) {
         return true;
     }
     $attributes = $attributes ? array_merge($this->getAttributes(), $attributes) : $this->getAttributes();
     $validator = Main::$app->connection->validator->make($attributes, $this->rules());
     $result = $validator->passes();
     if (!$result) {
         $this->errors = $validator->errors();
         foreach ($this->errors->getMessages() as $errors) {
             foreach ($errors as $error) {
                 Alert::add($error, Alert::ERROR);
             }
         }
         return false;
     }
     return true;
 }
Пример #7
0
 /**
  * Show specific alert type
  * @param  string $type
  * @return string
  */
 public function render()
 {
     if ($this->bag->any()) {
         $output = array();
         foreach ($this->bag->getMessages() as $type => $messages) {
             foreach ($messages as $message) {
                 // Prepare output
                 $output[] = array('type' => $type, 'data' => $message);
             }
         }
         //$json = new JsonResponse;
         //return json_encode($output);
         return $output;
     }
 }
Пример #8
0
 /**
  * Method to loop through errors and merge them into parent attribute
  * @param string     $attribute
  * @param integer     $index
  * @param MessageBag $errors
  */
 private function addCallAnotherErrors($attribute, MessageBag $errors)
 {
     foreach ($errors->getMessages() as $nestedAttribute => $messages) {
         foreach ($messages as $message) {
             $specifier = $this->makeSpecifier('call_another');
             $specifier = str_replace(':attribute', $attribute, $specifier);
             $this->messages->add($attribute, "{$specifier} {$message}");
         }
     }
 }
Пример #9
0
 /**
  * Sets a validation error flash message.
  *
  * @param MessageBag $errors
  * @param string $message
  */
 public function validation(MessageBag $errors, $message = 'Form validation failed')
 {
     $this->error($message);
     $this->session->flash('flash_notification.validation', $errors->getMessages());
 }
Пример #10
0
 /**
  * Get the raw messages in the message bag.
  *
  * @return array
  */
 public function getMessages()
 {
     return $this->messages->getMessages();
 }
Пример #11
0
 /**
  * Merge the errors into the multiple form builder.
  *
  * @param MessageBag $errors
  */
 protected function mergeErrors(MessageBag $errors)
 {
     foreach ($errors->getMessages() as $field => $message) {
         $this->builder->addFormError($field, implode('<br>', $message));
     }
 }
Пример #12
0
 /**
  * Validation error.
  *
  * @param  array  $messages
  * @return string
  */
 protected function error_422($messages)
 {
     // Get message bag from validator.
     if ($messages instanceof MessageProviderInterface) {
         $messages = $messages->getMessageBag();
     }
     // Get validation message bag.
     if (!$messages instanceof MessageBag) {
         $messages = new MessageBag($messages);
     }
     $content = array();
     // Re-format error messages.
     foreach ($messages->getMessages() as $field => $message) {
         $error = array('field' => $field, 'message' => current($message));
         array_push($content, $error);
     }
     return $this->make($content, 'error_422');
 }
Пример #13
0
 /**
  * Merge a message bag
  * @param  Illuminate\Support\MessageBag $bag 
  * @return Iyoworks\Support\AlertBag       
  */
 public function mergeBag(MessageBag $bag)
 {
     $this->merge($bag->getMessages());
     return $this;
 }