{"record":{"id":"82035ed9e54d3a36","repo":"laravel/framework","slug":"non-associative-array-passed-to-decrementeach-meth","errorCode":null,"errorMessage":"Non-associative array passed to decrementEach method.","messagePattern":"Non-associative array passed to decrementEach method\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Builder.php","lineNumber":4494,"sourceCode":"        return $this->decrementEach([$column => $amount], $extra);\n    }\n\n    /**\n     * Decrement 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 decrementEach(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 decrement amount for column: '$column'.\");\n            } elseif (! is_string($column)) {\n                throw new InvalidArgumentException('Non-associative array passed to decrementEach 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     * Delete records from the database.\n     *\n     * @param  mixed  $id\n     * @return int\n     */\n    public function delete($id = null)\n    {\n        // If an ID is passed to the method, we will set the where clause to check the\n        // ID to let developers to simply and quickly remove a single row from this","sourceCodeStart":4476,"sourceCodeEnd":4512,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Builder.php#L4476-L4512","documentation":"decrementEach() needs column-name => amount pairs to wrap and reference each column. A list-style array (numeric keys) has no column names, so it throws InvalidArgumentException to refuse the call rather than emit ambiguous SQL.","triggerScenarios":"->decrementEach([1, 2, 3]) (numeric keys), or ->decrementEach(['stock', 'reserved']) where keys become numeric indices.","commonSituations":"Passing a flat list of column names expecting a default of -1; passing the wrong variable; refactoring that loses the associative structure.","solutions":["Pass an associative map with numeric amounts: ['stock' => 1, 'reserved' => 1].","Convert a column list to a -1 map: array_fill_keys($columns, 1).","Use individual decrement() calls if custom per-column logic is needed."],"exampleFix":"// before\n->decrementEach(['stock', 'reserved'])\n\n// after\n->decrementEach(['stock' => 1, 'reserved' => 1])","handlingStrategy":"validation","validationCode":"if (array_is_list($columns)) {\n    throw new InvalidArgumentException('decrementEach requires column => amount pairs.');\n}\n$query->decrementEach($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: ['stock' => 1].","Use array_fill_keys($columns, 1) to convert a list into a -1 map.","Test that the keys are strings when constructing counter maps dynamically."],"tags":["query-builder","decrement","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"}