{"record":{"id":"77d1f4a1d62c7e5f","repo":"laravel/framework","slug":"non-associative-array-passed-to-incrementeach-meth","errorCode":null,"errorMessage":"Non-associative array passed to incrementEach method.","messagePattern":"Non-associative array passed to incrementEach method\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Builder.php","lineNumber":4452,"sourceCode":"        return $this->incrementEach([$column => $amount], $extra);\n    }\n\n    /**\n     * Increment the given column's values by the given amounts.\n     *\n     * @param  array<string, float|int|numeric-string>  $columns\n     * @param  array<string, mixed>  $extra\n     * @return int<0, max>\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function incrementEach(array $columns, array $extra = [])\n    {\n        foreach ($columns as $column => $amount) {\n            if (! is_numeric($amount)) {\n                throw new InvalidArgumentException(\"Non-numeric value passed as increment amount for column: '$column'.\");\n            } elseif (! is_string($column)) {\n                throw new InvalidArgumentException('Non-associative array passed to incrementEach method.');\n            }\n\n            $columns[$column] = $this->raw(\"{$this->grammar->wrap($column)} + $amount\");\n        }\n\n        return $this->update(array_merge($columns, $extra));\n    }\n\n    /**\n     * Decrement a column's value by a given amount.\n     *\n     * @param  string  $column\n     * @param  float|int  $amount\n     * @return int<0, max>\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function decrement($column, $amount = 1, array $extra = [])","sourceCodeStart":4434,"sourceCodeEnd":4470,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Builder.php#L4434-L4470","documentation":"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.","triggerScenarios":"->incrementEach([1, 2, 3]) (numeric keys), or ->incrementEach(['views', 'clicks']) where keys are the column names but values default to integer indices.","commonSituations":"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.","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."],"exampleFix":"// before\n->incrementEach(['views', 'clicks'])\n\n// after\n->incrementEach(['views' => 1, 'clicks' => 1])","handlingStrategy":"validation","validationCode":"if (array_is_list($columns)) {\n    throw new InvalidArgumentException('incrementEach requires column => amount pairs.');\n}\n$query->incrementEach($columns);","typeGuard":"function isColumnAmountMap(array $a): bool\n{\n    foreach (array_keys($a) as $k) {\n        if (! is_string($k)) {\n            return false;\n        }\n    }\n    return true;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["query-builder","increment","database","array-shape"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}