当前位置: 首页>>代码示例>>PHP>>正文


PHP Validation\Validator类代码示例

本文整理汇总了PHP中Illuminate\Contracts\Validation\Validator的典型用法代码示例。如果您正苦于以下问题:PHP Validator类的具体用法?PHP Validator怎么用?PHP Validator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Validator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: formatErrors

 protected function formatErrors(Validator $validator)
 {
     if (count($validator->errors()->getMessages()) > 8) {
         return [trans('messages.many-errors')];
     }
     return $validator->errors()->all();
 }
开发者ID:Tisho84,项目名称:conference,代码行数:7,代码来源:DepartmentRequest.php

示例2: formatErrors

 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;
 }
开发者ID:natalieduong,项目名称:konnection,代码行数:26,代码来源:CreateActivityRequest.php

示例3: formatErrors

 public function formatErrors(Validator $validator)
 {
     foreach ($validator->errors()->all() as $error) {
         Notifications::add($error, 'danger');
     }
     return $validator->errors()->getMessages();
 }
开发者ID:vitos8686,项目名称:0ez,代码行数:7,代码来源:StoreCategoryRequest.php

示例4: failedValidation

 /**
  * 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);
 }
开发者ID:dingo,项目名称:api,代码行数:14,代码来源:FormRequest.php

示例5: validateWith

 /**
  * 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);
     }
 }
开发者ID:CupOfTea696,项目名称:CardsAgainstTea,代码行数:14,代码来源:Controller.php

示例6: failedValidation

 /**
  * 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);
 }
开发者ID:jenky,项目名称:laravel-api-starter,代码行数:14,代码来源:Request.php

示例7: validatePhone

 /**
  * 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;
 }
开发者ID:summer11123,项目名称:Laravel-Phone,代码行数:44,代码来源:PhoneValidator.php

示例8: failedValidationResponse

 /**
  * 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));
 }
开发者ID:gdgfoz,项目名称:codelab-todo-api,代码行数:13,代码来源:BaseRequest.php

示例9: formatErrors

 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();
 }
开发者ID:josmel,项目名称:buen,代码行数:8,代码来源:RequestWservice.php

示例10: failedValidation

 protected function failedValidation(Validator $validator)
 {
     if ($this->ajax()) {
         $this->session()->flashInput($this->all());
         $this->session()->flash('errors', $validator->getMessageBag());
     }
     parent::failedValidation($validator);
 }
开发者ID:vainproject,项目名称:vain-blog,代码行数:8,代码来源:CommentFormRequest.php

示例11: throwStoreResourceFailedException

 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);
     }
 }
开发者ID:muhammadshakeel,项目名称:laravel-api-boilerplate-oauth,代码行数:8,代码来源:BaseController.php

示例12: store

 /**
  * 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;
 }
开发者ID:system3d,项目名称:consultas-tecnicas,代码行数:14,代码来源:UserController.php

示例13: extendUpdate

 /**
  * 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'));
         }
     });
 }
开发者ID:quetzyg,项目名称:control,代码行数:16,代码来源:Role.php

示例14: formatErrors

 /**
  * 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];
 }
开发者ID:bitller,项目名称:nova,代码行数:16,代码来源:AjaxRequest.php

示例15: formatValidationErrors

 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();
 }
开发者ID:Aphix-Labs,项目名称:laravel-aphix-boilerplate,代码行数:9,代码来源:UsersController.php


注:本文中的Illuminate\Contracts\Validation\Validator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。