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

多维数组验证使用requiredIf时,无法使用

Open CyanChenQ opened this issue 4 years ago • 0 comments

// 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;
    }

CyanChenQ avatar Feb 01 '21 03:02 CyanChenQ