php-validate icon indicating copy to clipboard operation
php-validate copied to clipboard

Improve eachValidator ?

Open yoh opened this issue 6 years ago • 1 comments
trafficstars

Hi ! Thank you for this lib !

Is there a way to combine eachValidator with FieldValidation and filters ? Perhaps with something like this :

$v = Inhere\Validate\FieldValidation::check(['array' => [
    [
        'string' => "   some words    ",
        'int' => "44",
    ], [
        'string' => "   some letters    ",
        'int' => "   456  ",
    ]
]], [
    ['array.*.int', 'each|required|int', 'filter' => 'int'],
    ['array.*.string', 'each|required|string', 'filter' => 'trim'],
]);

Bonus question : is there a way to get index/key in the errors array ? Currently we don't know which element is/are in error ?

  0 => array:2 [▼
    "name" => "array.*.int"
    "msg" => "array.*.int must be through the int verify"
  ]

yoh avatar Sep 01 '19 16:09 yoh

hi @yoh if use wildcard *, will skip apply filters. :(

inhere avatar Apr 26 '20 14:04 inhere