Example #1
0
 public function error()
 {
     if ($this->validator->errors()) {
         return $this->validator->errors()->first();
     }
     return null;
 }
 /**
  * Call the custom plan eligibility checker callback.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @param  \Laravel\Spark\Plan  $plan
  * @return void
  */
 protected function callCustomCallback($validator, $plan)
 {
     try {
         if (!Spark::eligibleForTeamPlan($this->route('team'), $plan)) {
             $validator->errors()->add('plan', 'This team is not eligible for this plan.');
         }
     } catch (IneligibleForPlan $e) {
         $validator->errors()->add('plan', $e->getMessage());
     }
 }
 /**
  * Validates the model.
  *
  * @param array $customRules
  * @param array $customMessages
  * @param array $attributeNames
  *
  * @return bool
  */
 protected function runValidation(array $customRules = [], array $customMessages = [], array $attributeNames = [])
 {
     $rules = empty($customRules) ? $this->getRules() : $customRules;
     $messages = empty($customMessages) ? $this->getCustomMessages() : $customMessages;
     $attributeNames = empty($attributeNames) ? $this->getAttributeNames() : $attributeNames;
     $attributes = $this->prepareAttributes();
     $this->validator = $this->makeValidator($attributes, $rules, $messages);
     $this->validator->setAttributeNames($attributeNames);
     $success = $this->validator->passes();
     if (!$success) {
         $this->setErrors($this->validator->errors());
     }
     return $success;
 }
 /**
  * ValidationException constructor.
  *
  * @author Morten Rugaard <*****@*****.**>
  * @param  \Illuminate\Validation\Validator $validator
  * @param  array                            $errorCodes
  * @param  array                            $headers
  * @param  bool                          $report
  * @param  string                           $severity
  */
 public function __construct(IlluminateValidator $validator, array $errorCodes, array $headers = [], $report = false, $severity = 'error')
 {
     // Parse failed rules
     $failedRules = $this->parseFailedRules($validator->failed());
     // Set message of exception
     $errorMessages = $validator->errors();
     if ($errorMessages->count() > 1) {
         $message = 'Multiple validation rules failed. See "errors" for more details.';
     } else {
         $message = $errorMessages->first();
     }
     // Custom error codes container
     $customErrorCodes = [];
     // Custom error codes takes priority, so let's see
     // if one of our failed rules has one
     $failedRulesCustomErrorCodes = array_intersect(array_keys($errorCodes), $failedRules);
     if (!empty($failedRulesCustomErrorCodes)) {
         foreach ($failedRulesCustomErrorCodes as $failedRule) {
             $customErrorCodes[$errorCodes[$failedRule]] = $errorCodes[$failedRule];
         }
     }
     // Determine exception and status code
     $exceptionCode = $statusCode = !empty($customErrorCodes) ? array_shift($customErrorCodes) : 412;
     // Construct exception
     parent::__construct($message, $exceptionCode, $headers, $report, $severity);
     // Fill exception's error bag with validation errors
     $this->setErrors($errorMessages);
     // Set status code
     $this->setStatusCode($statusCode, $errorMessages->first());
     // Do not send report
     $this->dontReport();
 }
 /**
  * Check if a field has any errors
  *
  * @param $field
  * @return mixed
  */
 public function fieldHasError($field)
 {
     if (!isset($this->validator)) {
         $this->validate();
     }
     return isset($this->validator->errors()->getMessages()[$field]);
 }
 public function __construct(Validator $validator)
 {
     $errors = '';
     foreach ($validator->errors()->getMessages() as $key => $messages) {
         $errors .= implode(' ', $messages) . ' ';
     }
     parent::__construct(422, trim($errors));
 }
Example #7
0
 protected function formatErrors(Validator $validator)
 {
     $errors = $this->parseErrorRest($validator->errors()->getMessages());
     $response = new ResponseWService();
     $response->setDataResponse(ResponseWService::HEADER_HTTP_RESPONSE_SOLICITUD_INCORRECTA, array(), $errors, 'Datos Invalidos del formulario');
     $response->response();
     //            return $validator->errors()->all();
 }
Example #8
0
 /**
  * Validate that the maximum number of teams hasn't been exceeded.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
  * @return void
  */
 protected function validateMaximumTeamsNotExceeded($validator, $user)
 {
     if (!($plan = $user->sparkPlan())) {
         return;
     }
     if (is_null($plan->teams)) {
         return;
     }
     if ($plan->teams <= $user->ownedTeams()->count()) {
         $validator->errors()->add('name', 'Please upgrade your subscription to create more teams.');
     }
 }
 public static function appendErrors(\Illuminate\Validation\Validator $validator)
 {
     foreach ($validator->errors()->all() as $message) {
         Session::push('field_validation_errors', $message);
     }
 }
 /**
  * Validate that the request's location information agrees.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @return void
  */
 protected function validateLocation($validator)
 {
     if (!app(StripeService::class)->tokenIsForCountry($this->stripe_token, $this->country)) {
         $validator->errors()->add('country', 'This country does not match the origin country of your card.');
     }
 }
 protected function formatErrors(Validator $validator)
 {
     Session::flash('am-alert', ['type' => 'warning', 'data' => array_values($validator->errors()->all())]);
     return $validator->errors()->all();
 }
Example #12
0
 protected function formatValidationErrors(Validator $validator)
 {
     return $validator->errors()->all('<li>:message</li>');
 }
Example #13
0
 /**
  * Set error messages from a validator instance.
  *
  * @param Validator
  *
  * @return $this
  */
 public function validator(Validator $validator)
 {
     $this->attributes['message'] = $validator->errors()->all();
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 protected function formatValidationErrors(Validator $validator)
 {
     return ['errno' => 1, 'msg' => $validator->errors()->first()];
 }
Example #15
0
 protected function formatValidationErrors(Validator $validator)
 {
     $errors = ['status' => 400, 'errors' => $validator->errors()->getMessages()];
     return $errors;
 }
 /**
  * 
  * @param Validator $object
  */
 public function setValidator(Validator $object)
 {
     $this->_messages = $object->errors()->getMessages();
     $this->_rules = $object->failed();
 }
Example #17
0
 /**
  * Format the errors from the given Validator instance.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @return array
  */
 protected function formatErrors(Validator $validator)
 {
     return $validator->errors()->all();
 }
Example #18
0
 /**
  * 获取验证器的错误消息
  *
  * @param Validator $validator
  *
  * @return array
  */
 protected function validatorMessage(Validator $validator)
 {
     return array_flatten($validator->errors()->getMessages());
 }
Example #19
0
 protected function formatErrors(Validator $validator)
 {
     return ['error' => $validator->errors()->all()[0]];
 }
 protected function throwValidationException(Request $req, Validator $val)
 {
     $errors = $val->errors()->toArray();
     throw new InvalidInputException($errors);
 }
Example #21
0
 public static function loginFailValidate(Validator $validator)
 {
     $message = 'ошибка авторизации (валидация)';
     $data = ['message' => $message, 'error' => $validator->errors()->first()];
     self::report(self::LOGIN_FAIL_VALIDATE, $data);
 }
 /**
  * Get the errors for the exception
  * @return MessageBag Message bad instance
  */
 public function getErrors()
 {
     return $this->validator->errors();
 }
Example #23
0
 /**
  * @return MessageBag
  */
 protected function getValidationErrors()
 {
     return $this->validation->errors();
 }
 public function __construct(Validator $validator)
 {
     parent::__construct(422, $validator->errors()->getMessages());
 }
 /**
  * Call the custom plan eligibility checker callback.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @param  \Laravel\Spark\Plan  $plan
  * @return void
  */
 protected function callCustomCallback($validator, $plan)
 {
     try {
         if (!Spark::eligibleForPlan($this->user(), $plan)) {
             $validator->errors()->add('plan', 'You are not eligible for this plan.');
         }
     } catch (IneligibleForPlan $e) {
         $validator->errors()->add('plan', $e->getMessage());
     }
 }
 /**
  * @return array
  */
 public function getErrorMessages()
 {
     return $this->validator->errors()->getMessages();
 }
Example #27
0
 /**
  * Validate that the provided coupon actually exists on Stripe.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @param  \Illuminate\Http\Request  $request
  * @return void
  */
 protected function validateCoupon($validator, Request $request)
 {
     try {
         $coupon = StripeCoupon::retrieve($request->coupon, ['api_key' => config('services.stripe.secret')]);
         if ($coupon && $coupon->valid) {
             return;
         }
     } catch (Exception $e) {
         //
     }
     $validator->errors()->add('coupon', 'The provided coupon code is invalid.');
 }
 /**
  * Create a new validation error with messages from a validator.
  *
  * @param Validator $validator
  * @return ValidationError
  */
 public static function fromValidator(Validator $validator)
 {
     return new ValidationError($validator->errors()->toArray());
 }
 /**
  * Format the errors from the given Validator instance.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @return array
  */
 protected function formatErrors(Validator $validator)
 {
     return $validator->errors()->getMessages();
 }
Example #30
0
 public static function fromValidator(Validator $validator)
 {
     return new self($validator->errors(), $validator->getData());
 }