php-validate
php-validate copied to clipboard
多维数组验证使用requiredIf时,无法使用
// src/Traits/ScopedValidatorsTrait.php
public function requiredIf(string $field, $fieldVal, string $anotherField, $values): ?bool
{
// 此处验证二维数组字段时,$anotherField可能时‘test.field1’, isset为false
if (isset($this->data[$anotherField])) {
$anotherVal = $this->data[$anotherField];
// if (in_array($anotherVal, (array)$values, true)) {
if (Helper::inArray($anotherVal, (array)$values)) {
return $this->required($field, $fieldVal);
}
}
return null;
}