Skip to content

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

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions