本文整理汇总了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();
}
示例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;
}
示例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;
}