#Validation of array top-level star behavior not as expected

2 messages · Page 1 of 1 (latest)

upper mauve
#

When I create a Validator for each element of an Array with a top-level * I get double the amount of rules as Array Elements. (Laravel 9.50.2)

        $data = [8, 9, 10];

        $validator = Validator::make($data, [
            '*' => 'required|integer',
        ]);
        $validator->validate();

  #data: array:3 [
    0 => 8
    1 => 9
    2 => 10
  ]
  #initialRules: array:1 [
    "*" => "required|integer"
  ]
  #rules: array:6 [
    0 => array:2 [
      0 => "required"
      1 => "integer"
    ]
    1 => array:2 [
      0 => "required"
      1 => "integer"
    ]
    2 => array:2 [
      0 => "required"
      1 => "integer"
    ]
    3 => array:2 [
      0 => "required"
      1 => "integer"
    ]
    4 => array:2 [
      0 => "required"
      1 => "integer"
    ]
    5 => array:2 [
      0 => "required"
      1 => "integer"
    ]
  ]
  #currentRule: null
  #implicitAttributes: array:1 [
    "*" => array:6 [
      0 => 0
      1 => 1
      2 => 2
      3 => 3
      4 => 4
      5 => 5
    ]
  ]
upper mauve
#

Issue is the array_merge

 public static function initializeAndGatherData($attribute, $masterData)
    {
        $data = Arr::dot(static::initializeAttributeOnData($attribute, $masterData));

        return array_merge($data, static::extractValuesForWildcards(
            $masterData, $data, $attribute
        ));
    }