I'm using Respect/Validation and I created the following rules to validate and associative array:
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
)
);
and when I validate an array, it works fine but if some of mandatory keys are missing (let's say "company" key) I always get an error message like:
- Must have keys { "name", "company", "type", "country", "comment" }
But I would like to customize the error messages and get something like:
"company" field is missing
I've tried:
$errors = $exception->findMessages([
...
'keyset' => '{{name}} field is missing',
....
]);
but {{name}}
includes the whole array with key and values...
Is there any way to get that customize error message? should I include another {{placeholder}}
?
Thanks in advance