Overtrue\Validation\Validator::each PHP Method

each() public method

Define a set of rules that apply to each element in an array attribute.
public each ( string $attribute, string | array $rules )
$attribute string
$rules string | array
    public function each($attribute, $rules)
    {
        $data = array_get($this->data, $attribute);
        if (!is_array($data)) {
            if ($this->hasRule($attribute, 'Array')) {
                return;
            }
            throw new \InvalidArgumentException('Attribute for each() must be an array.');
        }
        foreach ($data as $dataKey => $dataValue) {
            foreach ($rules as $ruleValue) {
                $this->mergeRules("{$attribute}.{$dataKey}", $ruleValue);
            }
        }
    }
Validator