{"id":"a537c8dbd3f43e54","repo":"laravel/framework","slug":"non-numeric-value-passed-as-decrement-amount-for-c","errorCode":null,"errorMessage":"Non-numeric value passed as decrement amount for column: '$column'.","messagePattern":"Non-numeric value passed as decrement amount for column: '\\$column'\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Builder.php","lineNumber":4492,"sourceCode":"        }\n\n        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    {","sourceCodeStart":4474,"sourceCodeEnd":4510,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Query/Builder.php#L4474-L4510","documentation":"Thrown by decrementEach when one of the per-column amounts fails is_numeric(). decrementEach iterates an associative column => amount map and validates each amount, naming the offending column. It is the multi-column analogue of the single decrement guard.","triggerScenarios":"`decrementEach(['stock' => $req->stock, 'reserved' => $req->r])` where one value is non-numeric. Reusing the same input map for incrementEach and decrementEach without re-validating.","commonSituations":"Bulk inventory adjustment endpoints; order processing that decrements several stock counters from a form; converting individual decrement() calls into decrementEach() and inheriting unvalidated inputs.","solutions":["Validate every amount: `$request->validate(['stock' => 'numeric', 'reserved' => 'numeric']);`.","Cast each value before building the map.","Use the named column in the error to pinpoint the bad key.","Separate free-text fields from numeric adjustment maps."],"exampleFix":"// before\n$model->decrementEach(['stock' => $req->stock, 'reserved' => $req->reserved]);\n// => Non-numeric value passed as decrement amount for column: 'reserved'.\n\n// after\n$amounts = collect(['stock','reserved'])\n    ->mapWithKeys(fn ($c) => [$c => (float) $request->input($c, 0)])\n    ->toArray();\n$model->decrementEach($amounts);","handlingStrategy":"validation","validationCode":"foreach ($amounts as $col => $amt) {\n    if (! is_numeric($amt)) {\n        throw new \\InvalidArgumentException(\"Amount for {$col} must be numeric.\");\n    }\n}\n$model->decrementEach($amounts);","typeGuard":"/** @param array<string, int|float|numeric-string> $a */\nfunction allAmountsNumeric(array $a): bool\n{\n    return array_all($a, fn($v) => is_numeric($v));\n}","tryCatchPattern":"// Validate the whole map before calling decrementEach; the error names the offending column.","preventionTips":["Validate batch adjustment inputs with array.* numeric rules.","Cast each value before building the map.","Use the column name in the error to locate the bad key."],"tags":["query-builder","decrement","numeric","invalid-argument"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}