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
- Make the columns and values arrays come from a single source of truth so their lengths cannot diverge.
- Add an explicit count() assertion in your calling code with a clearer message before reaching the builder.
- 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
- Drive columns and values from the same source so lengths stay in sync.
- Add a count() assertion in calling code with a domain-specific message.
- Favor plain where() chains unless you specifically need row-value tuple SQL.
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
- Invalid binding type
- Order direction must be a SortDirection, "asc" or "desc".
- The chunk size should be at least 1
- A subquery must be a query builder instance, a Closure, or…
- Collection given to whereAttachedTo method may not be empty.
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 $thisView on GitHub (pinned to e0f6eb3518)