示例#1
1
 /**
  * Get validation errors
  *
  * @return array
  */
 public function getErrors()
 {
     if (!$this->validator || !$this->validator instanceof Validator) {
         throw new \InvalidArgumentException(sprintf('Form %s was not validated. To validate it, call "isValid" method before retrieving the errors', get_class($this)));
     }
     return $this->validator->getMessageBag()->getMessages();
 }
 protected function failedValidation(Validator $validator)
 {
     if ($this->ajax()) {
         $this->session()->flashInput($this->all());
         $this->session()->flash('errors', $validator->getMessageBag());
     }
     parent::failedValidation($validator);
 }
 protected function failedValidation(Validator $validator)
 {
     $messages = $validator->errors();
     if ($messages->has('email', '<p>:The email has already been taken.</p>')) {
         $subscription = Subscription::where('email', $this->request->get('email'))->first();
         if (!$subscription->confirmed) {
             $this->mailer->sendEmailConfirmationFor($subscription);
         } else {
             $messages = ['email.unique:subscriptions' => 'That email address is already signed up'];
             $validator->getMessageBag()->merge($messages);
             $this->mailer->sendEmailRejectionFor($subscription);
         }
     }
     throw new HttpResponseException($this->response($this->formatErrors($validator)));
 }
示例#4
1
 /**
  * Formats the validators errors to allow any number of security questions.
  *
  * @param Validator $validator
  *
  * @return array
  */
 protected function formatErrors(Validator $validator)
 {
     $errors = $validator->getMessageBag()->toArray();
     $processed = [];
     foreach ($errors as $key => $error) {
         $parts = explode('.', $key);
         // If we have exactly two parts, we can work with the error message.
         if (count($parts) === 2) {
             list($name, $key) = $parts;
             $field = sprintf('%s[%s]', $name, $key);
             $processed[$field] = $error;
         }
     }
     return $processed;
 }
 /**
  * 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();
 }
示例#6
1
 /**
  * Generates a Response with a 400 HTTP header and a given message from validator
  *
  * @param Validator $validator
  * @return ResponseFactory
  */
 public function errorWrongArgsValidator(Validator $validator)
 {
     return $this->errorWrongArgs($validator->getMessageBag()->toArray());
 }
 /**
  * @param Validator $validator
  */
 protected function addValidatorErrors(Validator $validator)
 {
     $messages = $validator->getMessageBag();
     $this->addErrors($this->errorFactory->filterParametersMessages($messages));
 }
示例#8
1
 /**
  * Creates an alert from the result of validator.
  *
  * The type of the alert will be TYPE_VALIDATION
  *
  * @param Validator $validator
  * @param null $title
  * @param null $view
  */
 public function pushValidation(Validator $validator, $title = null, $view = null)
 {
     $messages = $validator->getMessageBag()->all();
     $this->push($messages, Alert::TYPE_VALIDATION, $title, $view);
 }
 /**
  * Get the error data.
  *
  * @return array|null
  */
 public function getData()
 {
     return ['fields' => $this->validator->getMessageBag()->toArray()];
 }
 /**
  * @param Validator $validator
  */
 protected function addValidatorErrors(Validator $validator)
 {
     $messages = $validator->getMessageBag();
     $this->addErrors($this->errorFactory->resourceInvalidAttributesMessages($messages));
 }
示例#11
1
 /**
  * Throw the failed validation exception.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Illuminate\Contracts\Validation\Validator  $validator
  * @return void
  *
  * @throws ResourceException
  */
 protected function throwValidationException(Request $request, $validator)
 {
     throw new ResourceException($this->failedValidationMessage, $validator->getMessageBag());
 }
示例#12
1
 /**
  * Format the validation errors to be returned.
  *
  * @param  \Illuminate\Contracts\Validation\Validator  $validator
  * @return array
  */
 protected function formatValidationErrors(\Illuminate\Contracts\Validation\Validator $validator)
 {
     zbase_alert(\Zbase\Zbase::ALERT_ERROR, $validator->getMessageBag(), ['formvalidation' => true]);
     return $validator->errors()->getMessages();
 }