当前位置: 首页>>代码示例>>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;未经允许,请勿转载。