我想创建此扩展验证。
Validator::extend('my_custom_validation_rule', function ($attribute, $value, $parameters) {
// I guess I should be setting the error message for this here.(Its dynamic)
// We can return true or false here depending upon our need.
}
我会这样使用这个规则
'my_field' => 'required|my_custom_validation_rule'
,
我想对“ my_custom_validation_rule
”的错误使用一些动态消息
我无法从文档中找到有关它的信息。反正有做吗?
该extend
方法允许将消息作为第三个参数传递:
Validator::extend('my_custom_validation_rule', function ($attribute, $value, $parameters) {
// ...
}, 'my custom validation rule message');
默认情况下,您只能使用动态变量,即:attribute
。如果您想添加更多使用Validator::replacer()
:
Validator::replacer('my_custom_validation_rule', function($message, $attribute, $rule, $parameters){
return str_replace(':foo', $parameters[0], $message);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句