laravel/framework · error · InvalidArgumentException
Non-associative array passed to incrementEach method.
Error message
Non-associative array passed to incrementEach method.
What it means
incrementEach() needs column-name => amount pairs so it can wrap and reference each column. A list-style array (numeric keys) means there is no column name to update, so it throws InvalidArgumentException to refuse the call rather than emit ambiguous SQL.
Solutions
- Pass an associative map with numeric amounts: ['views' => 1, 'clicks' => 1].
- Convert a column list to a +1 map: array_fill_keys($columns, 1).
- Use a single increment() loop if you really need per-column custom logic.
Example fix
// before ->incrementEach(['views', 'clicks']) // after ->incrementEach(['views' => 1, 'clicks' => 1])
Defensive patterns
Strategy: validation
Validate before calling
if (array_is_list($columns)) {
throw new InvalidArgumentException('incrementEach requires column => amount pairs.');
}
$query->incrementEach($columns); Type guard
function isColumnAmountMap(array $a): bool
{
foreach (array_keys($a) as $k) {
if (! is_string($k)) {
return false;
}
}
return true;
} Prevention
- Build maps explicitly: ['views' => 1].
- Use array_fill_keys($columns, 1) to convert a list into a +1 map.
- Add a unit test that asserts the keys are strings when constructing counter maps.
When it happens
Trigger: ->incrementEach([1, 2, 3]) (numeric keys), or ->incrementEach(['views', 'clicks']) where keys are the column names but values default to integer indices.
Common situations: Passing a flat list of column names expecting them to default to +1; passing the wrong variable (a list of names instead of a map); refactoring that loses the associative structure.
Related errors
- Non-associative array passed to decrementEach method.
- Non-numeric value passed as increment amount for column…
- Non-numeric value passed to increment method.
- A subquery must be a query builder instance, a Closure, or…
- $count records were found.
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/77d1f4a1d62c7e5f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Database/Query/Builder.php:4452
return $this->incrementEach([$column => $amount], $extra);
}
/**
* Increment the given column's values by the given amounts.
*
* @param array<string, float|int|numeric-string> $columns
* @param array<string, mixed> $extra
* @return int<0, max>
*
* @throws \InvalidArgumentException
*/
public function incrementEach(array $columns, array $extra = [])
{
foreach ($columns as $column => $amount) {
if (! is_numeric($amount)) {
throw new InvalidArgumentException("Non-numeric value passed as increment amount for column: '$column'.");
} elseif (! is_string($column)) {
throw new InvalidArgumentException('Non-associative array passed to incrementEach method.');
}
$columns[$column] = $this->raw("{$this->grammar->wrap($column)} + $amount");
}
return $this->update(array_merge($columns, $extra));
}
/**
* Decrement a column's value by a given amount.
*
* @param string $column
* @param float|int $amount
* @return int<0, max>
*
* @throws \InvalidArgumentException
*/
public function decrement($column, $amount = 1, array $extra = [])View on GitHub (pinned to e0f6eb3518)