本文整理汇总了PHP中Illuminate\Validation\Validator::getMessageBag方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::getMessageBag方法的具体用法?PHP Validator::getMessageBag怎么用?PHP Validator::getMessageBag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Validation\Validator
的用法示例。
在下文中一共展示了Validator::getMessageBag方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validationFails
public function validationFails(Validator $validator)
{
$this->success = false;
$this->errors = $validator->getMessageBag();
$this->validationErrors = $validator->getMessageBag();
return $this->toJson();
}
示例2: fetchMessages
/**
* fetch error messages from validator and optionally prepend them with a custom message
* @param Validator $validator
*/
protected function fetchMessages(Validator $validator)
{
/**
* $errors array is constructed like: field1 => array(0 => 'error message 1', 1 => 'error message 2' ...)
* I will prepend the custom error message (added by addValidation()) to this messages array per field
*/
$this->errors = $validator->getMessageBag()->getMessages();
foreach ($this->errors as $name => &$messages) {
if (!empty($this->validations[$name]['message'])) {
$attributeName = str_replace('_', ' ', $name);
$customMessage = str_replace(':attribute', $attributeName, $this->validations[$name]['message']);
array_unshift($messages, $customMessage);
}
}
}
示例3: getMessageBag
public function getMessageBag()
{
return $this->validator->getMessageBag();
}
示例4: setResponse
/**
* Set the response based on validation.
*
* @param Validator $validator
* @param FormBuilder $builder
*/
protected function setResponse(Validator $validator, FormBuilder $builder)
{
if (!$validator->passes()) {
$builder->setSave(false);
$bag = $validator->getMessageBag();
foreach ($bag->getMessages() as $field => $messages) {
foreach ($messages as $message) {
$builder->addFormError($field, $message);
}
}
$this->dispatch(new SetErrorMessages($builder));
}
$this->dispatch(new RepopulateFields($builder));
}
示例5: setResponse
/**
* Set the response based on validation.
*
* @param Validator $validator
* @param FormBuilder $builder
*/
protected function setResponse(Validator $validator, FormBuilder $builder)
{
if (!$validator->passes()) {
$builder->setSave(false)->setFormErrors($validator->getMessageBag());
$this->dispatch(new SetErrorMessages($builder));
}
$this->dispatch(new RepopulateFields($builder));
}