Replies: 2 comments 27 replies
-
In version 3.0, the array messages will look like this: [
'each' => [
'__root__' => 'These rules must pass for `["groups": [1, 2, 3, 4, 5], "permissions": ["perm1": true, "perm2": false, "perm3": "boom!"]]`',
'each.1' => [
'__root__' => 'Each item in `["groups": [1, 2, 3, 4, 5], "permissions": ["perm1": true, "perm2": false, "perm3": "boom!"]]` must be valid',
'boolVal.1' => '`[1, 2, 3, 4, 5]` must be a boolean value',
'boolVal.2' => '`["perm1": true, "perm2": false, "perm3": "boom!"]` must be a boolean value',
],
'each.2' => [
'__root__' => 'Each item in `["groups": [1, 2, 3, 4, 5], "permissions": ["perm1": true, "perm2": false, "perm3": "boom!"]]` must be valid',
'boolVal.1' => '`[1, 2, 3, 4, 5]` must be a boolean value',
'boolVal.2' => '`["perm1": true, "perm2": false, "perm3": "boom!"]` must be a boolean value',
],
],
] What do you think about that, I'm sure it's better, but I would like to know if that's good enough, |
Beta Was this translation helpful? Give feedback.
1 reply
-
However, I think what you want is a validation chain that looks like this: use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Validator as v;
$acl_update_request = [
15 => [
'groups' => [1, 2, 3, 4, 5],
'permissions' => [
'perm1' => true,
'perm2' => false,
'perm3' => 'boom!',
]
]
];
try {
v::arrayVal()
->each(
v::arrayVal()
->key('groups', v::arrayVal()->each(v::intVal()))
->key('permissions', v::arrayVal()->each(v::boolVal()))
)
->assert($acl_update_request);
} catch(NestedValidationException $exception) {
var_dump($exception->getMessages());
} That will then result into: [
'each' => 'permissions must be a boolean value',
] |
Beta Was this translation helpful? Give feedback.
26 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm evaluating various validation libraries in order to find one that is expressive and able to validate nested structures. Respect is great except that I can't find the path of the failed key. What I mean:
I can't get "15.permissions.perm3" in any way. W/o this feature validation loses half of its value. The goal is to get something like:
My case is quite a common one: fat forms and complex APIs. If validation can't say exactly what is wrong, the usage and debugging become a nightmare.
Are there any plans for tracking paths?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions