validator
validator copied to clipboard
Way to add error with custom value path
In rule handlers Result::addError() is added error message to current key and value path define path into key. Need ability to add error with globally path.
Example:
$result = (new Validator())->validate(
data: ['a' => 1, 'b' => 2],
rules: [
'a' => new Callback(function(){
$result = new Result();
$result->addError('message', valuePath: ['b']);
return $result;
})
],
);
// Errors:
// ['a.b' => ['message']]
Need additional ability add error to key b. May be implement it via adding method addError() to validation context object.
What's the use-case?
What's the use-case?
Forms: add error to another field or add error without fields (common errors).