當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。