protected function failedValidation(Validator $validator)
 {
     if ($this->ajax()) {
         $this->session()->flashInput($this->all());
         $this->session()->flash('errors', $validator->getMessageBag());
     }
     parent::failedValidation($validator);
 }
示例#2
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;
 }
 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
 /**
  * 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();
 }
 /**
  * Validates a phone number.
  *
  * @param  string                                     $attribute
  * @param  mixed                                      $value
  * @param  array                                      $parameters
  * @param  \Illuminate\Contracts\Validation\Validator $validator
  * @return bool
  * @throws \Propaganistas\LaravelPhone\Exceptions\InvalidParameterException
  * @throws \Propaganistas\LaravelPhone\Exceptions\NoValidCountryFoundException
  */
 public function validatePhone($attribute, $value, array $parameters, Validator $validator)
 {
     $this->attribute = $attribute;
     $this->data = $validator->getData();
     $this->parameters = array_map('strtoupper', $parameters);
     $this->determineCountries();
     $this->determineTypes();
     $this->checkLeftoverParameters();
     $phoneUtil = PhoneNumberUtil::getInstance();
     // Perform validation.
     foreach ($this->allowedCountries as $country) {
         try {
             // For default countries or country field, the following throws NumberParseException if
             // not parsed correctly against the supplied country.
             // For automatic detection: tries to discover the country code using from the number itself.
             $phoneProto = $phoneUtil->parse($value, $country);
             // For automatic detection, the number should have a country code.
             // Check if type is allowed.
             if ($phoneProto->hasCountryCode() && empty($this->allowedTypes) || in_array($phoneUtil->getNumberType($phoneProto), $this->allowedTypes)) {
                 // Automatic detection:
                 if ($country == 'ZZ') {
                     // Validate if the international phone number is valid for its contained country.
                     return $phoneUtil->isValidNumber($phoneProto);
                 }
                 // Force validation of number against the specified country.
                 return $phoneUtil->isValidNumberForRegion($phoneProto, $country);
             }
         } catch (NumberParseException $e) {
             // Proceed to default validation error.
         }
     }
     return false;
 }
示例#6
0
 /**
  * Get the response for a error validate.
  *
  * @param Validator $validator
  * @return \Illuminate\Http\Response
  */
 public function failedValidationResponse(Validator $validator)
 {
     if ($this->is('api/*')) {
         return \ResponseFractal::respondErrorWrongArgs($validator->errors());
     }
     return $this->response($this->formatErrors($validator));
 }
示例#7
0
 /**
  * Handle a failed validation attempt.
  *
  * @param \Illuminate\Contracts\Validation\Validator $validator
  *
  * @return mixed
  */
 protected function failedValidation(Validator $validator)
 {
     if ($this->container['request'] instanceof BaseRequest) {
         throw new ApiValidationException($validator->errors(), $this->getFailedValidationMessage($this->container['request']));
     }
     parent::failedValidation($validator);
 }
示例#8
0
 public function formatErrors(Validator $validator)
 {
     foreach ($validator->errors()->all() as $error) {
         Notifications::add($error, 'danger');
     }
     return $validator->errors()->getMessages();
 }
示例#9
0
文件: FormRequest.php 项目: dingo/api
 /**
  * Handle a failed validation attempt.
  *
  * @param \Illuminate\Contracts\Validation\Validator $validator
  *
  * @return void
  */
 protected function failedValidation(Validator $validator)
 {
     if ($this->container['request'] instanceof Request) {
         throw new ValidationHttpException($validator->errors());
     }
     parent::failedValidation($validator);
 }
 public function formatErrors(Validator $validator)
 {
     $repeatedAttendee = false;
     $emptyNames = false;
     $errors = $validator->errors()->all();
     foreach ($errors as $index => $error) {
         if (fnmatch('The selected user id.* is invalid.', $error)) {
             // Removes from array; can still iterate through array with foreach
             unset($errors[$index]);
             $repeatedAttendee = true;
         } else {
             if (fnmatch('The name.* field is required.', $error)) {
                 unset($errors[$index]);
                 $emptyNames = true;
             }
         }
     }
     // Pushes more descriptive error message onto array
     if ($repeatedAttendee) {
         array_push($errors, 'The same attendee has been entered in the attendance list more than once.');
     }
     if ($emptyNames) {
         array_push($errors, 'One of the names of the listed attendees has not been provided.');
     }
     return $errors;
 }
示例#11
0
 /**
  * Run the validation routine against the given validator.
  *
  * @param  \Illuminate\Contracts\Validation\Validator  $validator
  * @param  \Illuminate\Http\Request|null  $request
  * @return void
  */
 public function validateWith($validator, Request $request = null)
 {
     $request = $request ?: app('request');
     if ($validator->fails()) {
         $this->throwValidationException($request, $validation);
     }
 }
示例#12
0
 protected function formatErrors(Validator $validator)
 {
     if (count($validator->errors()->getMessages()) > 8) {
         return [trans('messages.many-errors')];
     }
     return $validator->errors()->all();
 }
 public function throwStoreResourceFailedException($message = 'Failed to store your requested resource.', Validator $validator = null)
 {
     if ($validator instanceof Validator) {
         throw new \Dingo\Api\Exception\StoreResourceFailedException($message, $validator->errors());
     } else {
         throw new \Dingo\Api\Exception\StoreResourceFailedException($message);
     }
 }
示例#14
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();
 }
示例#15
0
 /**
  * Format error messages for ajax requests
  *
  * @param Validator $validator
  * @return array
  * @internal param Request $request
  */
 protected function formatErrors(Validator $validator)
 {
     $errors = $validator->errors()->all();
     $error = '';
     foreach ($errors as $errorMessage) {
         $error = $errorMessage;
     }
     return ['success' => false, 'title' => trans('common.fail'), 'message' => $error];
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Validator $validator, Request $request)
 {
     $messages = $validator->errors();
     $request->session()->flash('status', 'Task was successful!');
     foreach ($messages->all() as $message) {
         print_r($message);
     }
     exit;
 }
示例#17
0
文件: Role.php 项目: quetzyg/control
 /**
  * Extend update validations.
  *
  * @param  \Illuminate\Contracts\Validation\Validator  $validator
  *
  * @return void
  */
 protected function extendUpdate(ValidatorResolver $validator)
 {
     $name = Keyword::make($validator->getData()['name']);
     $validator->after(function (ValidatorResolver $v) use($name) {
         if ($this->isRoleNameGuest($name)) {
             $v->errors()->add('name', trans('orchestra/control::response.roles.reserved-word'));
         }
     });
 }
 protected function formatValidationErrors(Validator $validator)
 {
     foreach ($validator->errors()->getMessages() as $key => $message) {
         if (starts_with($key, 'roles')) {
             $validator->errors()->add('roles', $message[0]);
         }
     }
     return $validator->errors()->getMessages();
 }
 /**
  * Returns validation errors, if any
  *
  * @return MessageBag
  */
 public function messages()
 {
     if (is_null($this->validator)) {
         $this->validate();
     }
     if (!$this->validator->fails()) {
         return App::make(MessageBag::class);
     }
     return $this->validator->messages();
 }
 /**
  * Returns validation errors, if any
  *
  * @return \Illuminate\Contracts\Support\MessageBag
  */
 public function messages()
 {
     if (is_null($this->validator)) {
         $this->validate();
     }
     if (!$this->validator->fails()) {
         return app('\\Illuminate\\Support\\Messagebag');
     }
     return $this->validator->messages();
 }
 public function validate()
 {
     if ($this->validator->fails()) {
         $messages = [];
         foreach ($this->validator->messages()->all("The :key variable is not defined or invalid") as $var => $message) {
             $messages[] = $message;
         }
         $msg = 'The .env file has some problems. Please check config/laravel-env-validator.php' . PHP_EOL . implode(PHP_EOL, $messages);
         throw new Exception($msg);
     }
 }
 /**
  * @param Validator $validator
  * @return array
  */
 protected function formatErrors(Validator $validator)
 {
     $messages = $validator->errors();
     $errors = [];
     foreach ($this->fields as $field) {
         if (!$messages->has($field)) {
             continue;
         }
         $errors[$field] = $messages->first($field);
     }
     return $errors;
 }
示例#23
0
 /**
  * @param Validator $validator
  * @return array
  */
 protected function formatErrors(Validator $validator)
 {
     $messages = $validator->errors();
     $fields = ['email', 'password', 'password_confirmation', 'token'];
     $errors = [];
     foreach ($fields as $field) {
         if (!$messages->has($field)) {
             continue;
         }
         $errors[$field] = $messages->first($field);
     }
     return $errors;
 }
示例#24
0
 /**
  * @param Validator $validator
  * @return array
  */
 protected function formatErrors(Validator $validator)
 {
     $messages = $validator->errors();
     $fields = ['product_code', 'product_price', 'product_page', 'product_discount', 'product_quantity'];
     $errors = [];
     foreach ($fields as $field) {
         if (!$messages->has($field)) {
             continue;
         }
         $errors[$field] = $messages->first($field);
     }
     return $errors;
 }
示例#25
0
 /**
  * @param Validator $validator
  * @return array
  */
 protected function formatErrors(Validator $validator)
 {
     $messages = $validator->errors();
     $fields = ['question_category_id', 'question_content', 'question_title'];
     $errors = [];
     foreach ($fields as $field) {
         if (!$messages->has($field)) {
             continue;
         }
         $errors[$field] = $messages->first($field);
     }
     return $errors;
 }
示例#26
0
 /**
  * Does validation fails with given data
  *
  * @return bool
  * @throws \Exception
  */
 public function fails()
 {
     if (is_null($this->validated)) {
         throw new \Exception("No data has been validated yet");
     }
     return $this->validated->fails();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(PaiementRequest $request)
 {
     $validator = Validator::make($request->all(), ['type_carte' => 'required|alpha', 'numero_carte' => 'required|size:16|alpha_num', 'cryptogramme' => 'required|max:255|alpha_num']);
     if ($validator->fails()) {
         return redirect('post/create')->withErros($validator)->withInput();
     }
 }
示例#28
0
 /**
  * Create a new user
  *
  * https://laravel.com/docs/5.1/validation
  * @param  array $data
  * @return User
  */
 public static function create(array $attributes = [])
 {
     $table = with(new static())->table;
     //$v = self::validator($data);
     $v = Validator::make($attributes, static::$rules);
     $return = null;
     if ($v->passes()) {
         parent::create($attributes);
         $lastid = \DB::getpdo()->lastinsertid();
         $return = $lastid;
     } else {
         //$messages = $v->errors();
         $return = $v;
     }
     return $table;
 }
 /**
  * {@inheritdoc}
  */
 protected function formatValidationErrors(Validator $validator)
 {
     return $validator->errors()->all();
 }
示例#30
0
 /**
  * Make validation error response.
  *
  * @param \Illuminate\Contracts\Validation\Validator $validator
  * @return \Illuminate\Http\JsonResponse
  */
 protected function respondValidationError(Validator $validator)
 {
     return json()->unprocessableError($validator->errors()->all());
 }