本文整理汇总了PHP中Illuminate\Validation\Validator::failed方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::failed方法的具体用法?PHP Validator::failed怎么用?PHP Validator::failed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Validation\Validator
的用法示例。
在下文中一共展示了Validator::failed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
public function validate()
{
$data = $this->toArray();
$this->validator = Validator::make($data, $this->getSingleValidator());
$result = !$this->validator->fails();
$this->failed = $this->validator->failed();
foreach ($this->getAllValidators() as $key => $validate) {
$validator = Validator::make($data[$key], $validate->getSingleValidator());
$result = !$validator->fails() && $result;
if ($validator->fails()) {
$this->failed = array_merge($this->failed, [$key => $validator->failed()]);
}
}
return $result;
}
示例2: __construct
/**
* ValidationException constructor.
*
* @author Morten Rugaard <moru@nodes.dk>
* @param \Illuminate\Validation\Validator $validator
* @param array $errorCodes
* @param array $headers
* @param bool $report
* @param string $severity
*/
public function __construct(IlluminateValidator $validator, array $errorCodes, array $headers = [], $report = false, $severity = 'error')
{
// Parse failed rules
$failedRules = $this->parseFailedRules($validator->failed());
// Set message of exception
$errorMessages = $validator->errors();
if ($errorMessages->count() > 1) {
$message = 'Multiple validation rules failed. See "errors" for more details.';
} else {
$message = $errorMessages->first();
}
// Custom error codes container
$customErrorCodes = [];
// Custom error codes takes priority, so let's see
// if one of our failed rules has one
$failedRulesCustomErrorCodes = array_intersect(array_keys($errorCodes), $failedRules);
if (!empty($failedRulesCustomErrorCodes)) {
foreach ($failedRulesCustomErrorCodes as $failedRule) {
$customErrorCodes[$errorCodes[$failedRule]] = $errorCodes[$failedRule];
}
}
// Determine exception and status code
$exceptionCode = $statusCode = !empty($customErrorCodes) ? array_shift($customErrorCodes) : 412;
// Construct exception
parent::__construct($message, $exceptionCode, $headers, $report, $severity);
// Fill exception's error bag with validation errors
$this->setErrors($errorMessages);
// Set status code
$this->setStatusCode($statusCode, $errorMessages->first());
// Do not send report
$this->dontReport();
}
示例3: failed
/**
* {@inheritDoc}
*/
public function failed()
{
return $this->validator->failed();
}
示例4: getFailedRules
/**
* @return array
*/
public function getFailedRules()
{
return $this->validator->failed();
}
示例5: setValidator
/**
*
* @param Validator $object
*/
public function setValidator(Validator $object)
{
$this->_messages = $object->errors()->getMessages();
$this->_rules = $object->failed();
}