我正在使用尊重/验证,并创建了以下规则来验证和关联数组:
Validator::keySet(
Validator::key( // mandatory, if included type: string, values: not null, not empty
'name',
Validator::stringType()->notEmpty()
),
Validator::key( // mandatory, if included type: string, values: not null, not empty
'company',
Validator::stringType()->notEmpty()
),
Validator::key( // mandatory, if included type: string, values: not null, not empty
'type',
Validator::stringType()->notEmpty()
),
Validator::key( // mandatory, if included type: string, values: not null, not empty
'country',
Validator::stringType()->notEmpty()
),
Validator::key( // optional, if included type: string, values: not null, not empty
'comment',
Validator::stringType()->notEmpty(),
false
)
);
当我验证一个数组时,它可以正常工作,但是如果缺少一些强制键(比如说“公司”键),我总是会收到如下错误消息:
- Must have keys { "name", "company", "type", "country", "comment" }
但我想自定义错误消息并得到类似的东西:
"company" field is missing
我试过了:
$errors = $exception->findMessages([
...
'keyset' => '{{name}} field is missing',
....
]);
但{{name}}
包括带有键和值的整个数组...
有什么方法可以获取自定义错误消息?我应该包括另一个{{placeholder}}
吗?
提前致谢