當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Validator::setAttributeNames方法代碼示例

本文整理匯總了PHP中Illuminate\Validation\Validator::setAttributeNames方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::setAttributeNames方法的具體用法?PHP Validator::setAttributeNames怎麽用?PHP Validator::setAttributeNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Validation\Validator的用法示例。


在下文中一共展示了Validator::setAttributeNames方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validate

 /**
  * Validate the form
  *
  * @param null $scope
  * @param null $options
  * @return mixed
  * @throws \Exception
  */
 private function validate()
 {
     if (isset($this->validator)) {
         throw new \Exception('Cannot validate the same form twice, use the existing result');
     }
     $fieldRules = $this->getFieldValidationRules($this->formHandler->getFormBlueprint()->getAll());
     $validationRules = $fieldRules['rules'];
     $validationAttributeNames = $fieldRules['names'];
     // Get validation rules from any assigned entities (models)
     foreach ($this->formHandler->getEntities() as $entity) {
         if (is_callable([$entity['entity'], 'getValidationRules'])) {
             try {
                 $entityRules = $entity['entity']->getValidationRules();
             } catch (\BadMethodCallException $e) {
                 $entityRules = [];
             }
             foreach ($entityRules as $field => $entityRule) {
                 // If we already have rules for that parameter, concatenate them
                 if (isset($validationRules[$field])) {
                     $validationRules[$field] .= '|' . $entityRule;
                 } else {
                     $validationRules[$field] = $entityRule;
                 }
             }
         }
     }
     $this->validator = \Validator::make($this->formHandler->getData(), $validationRules);
     $this->validator->setAttributeNames($validationAttributeNames);
     $this->isValid = $this->validator->passes();
 }
開發者ID:andyvenus,項目名稱:laravel-forms,代碼行數:38,代碼來源:LaravelValidatorExtension.php

示例2: validate

 /**
  * @param array $formData
  *
  * @throws FormValidationException
  */
 public function validate(array $formData)
 {
     // Instantiate validator instance by factory
     $this->validation = $this->validator->make($formData, $this->rules());
     $this->validation->setAttributeNames($this->setAttributeNames());
     // Validate
     if ($this->validation->fails()) {
         throw new FormValidationException('Validation Failed', $this->getValidationErrors());
     }
     return true;
 }
開發者ID:khoilv,項目名稱:cuongthuy,代碼行數:16,代碼來源:BaseForm.php

示例3: runValidation

 /**
  * 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;
 }
開發者ID:vinicius73,項目名稱:laravel-model-shield,代碼行數:23,代碼來源:ShieldValidator.php


注:本文中的Illuminate\Validation\Validator::setAttributeNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。