laravel/framework · error · InvalidArgumentException

The number of columns must match the number of values

Error message

The number of columns must match the number of values

What it means

whereRowValues() builds a row-value comparison such as (a, b) = (1, 2). The SQL is only well-formed when the column tuple and value tuple have the same arity, so the method hard-asserts count($columns) === count($values) and throws InvalidArgumentException otherwise.

Solutions

  1. Make the columns and values arrays come from a single source of truth so their lengths cannot diverge.
  2. Add an explicit count() assertion in your calling code with a clearer message before reaching the builder.
  3. Fall back to a chain of plain where() calls if the row-value form is not required.

Example fix

// before
->whereRowValues(['tenant_id', 'user_id'], '=', [$tenant])

// after
->whereRowValues(['tenant_id', 'user_id'], '=', [$tenant, $user])
Defensive patterns

Strategy: validation

Validate before calling

if (count($columns) !== count($values)) {
    throw new InvalidArgumentException('columns/values length mismatch');
}
$query->whereRowValues($columns, $operator, $values);

Prevention

When it happens

Trigger: ->whereRowValues(['col_a', 'col_b'], '=', [1]), or any call where the columns array and values array have different lengths.

Common situations: Building row-value filters from form input where one side was omitted; refactoring a query and forgetting to keep both arrays in sync; passing a single-element values array for a multi-column key.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/3a90ee9c263720ca. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Database/Query/Builder.php:2226

        return $this;
    }

    /**
     * Adds a where condition using row values.
     *
     * @param  array  $columns
     * @param  string  $operator
     * @param  array  $values
     * @param  string  $boolean
     * @return $this
     *
     * @throws \InvalidArgumentException
     */
    public function whereRowValues($columns, $operator, $values, $boolean = 'and')
    {
        if (count($columns) !== count($values)) {
            throw new InvalidArgumentException('The number of columns must match the number of values');
        }

        $type = 'RowValues';

        $this->wheres[] = ['type' => $type, 'columns' => $columns, 'operator' => $operator, 'values' => $values, 'boolean' => $boolean];

        $this->addBinding($this->cleanBindings($values));

        return $this;
    }

    /**
     * Adds an or where condition using row values.
     *
     * @param  array  $columns
     * @param  string  $operator
     * @param  array  $values
     * @return $this

View on GitHub (pinned to e0f6eb3518)