验证请求中的验证挂钩
答
您可以覆盖getValidatorInstance()
方法在自定义请求类是这样的:
protected function getValidatorInstance()
{
$validator = parent::getValidatorInstance();
// here you can apply hook (example hook taken from documentation):
$validator->after(function ($validator) {
if ($this->somethingElseIsInvalid()) {
$validator->errors()->add('field', 'Something is wrong with this field!');
}
});
return $validator;
}