手册里提到除了用Validator::extend()
之外。还可以直接扩展 Validator 类
例子 :
class CustomValidator extends Illuminate\Validation\Validator {
public function validateFoo($attribute, $value, $parameters)
{
return $value == 'foo';
}
}
疑问:
最后手册说要注册一下,但是这段代码应该写在哪呢?
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new CustomValidator($translator, $data, $rules, $messages);
});