我正在使用laravel 5.4进行自定义表单验证。但是为什么没有显示自定义错误消息?
Validator::extend('myCustomeValidator', function ($attribute, $value, $parameters, $validator) {
//some code here
return false;
});
return Validator::make($data, [
'myField' => 'myCustomeValidator',
]);
并将以下内容添加到文件中:ressources\lang\en\validation.php
如文档所建议:
'custom' => [
'myField' => [
'myCustomeValidator' => 'You made an error.',
],
],
错误已正确触发,但我得到的不是我的自定义错误消息:
validation.my_custome_validator
我想念什么?
您需要使用自定义验证规则的蛇形名称。以下是技巧:
'custom' => [
'myField' => [
'my_custome_validator' => 'You made an error.',
],
],
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句