{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Builder.php#L4474-L4510","documentation":"decrementEach() applies a numeric delta to each column in an associative map. For every entry it checks is_numeric($amount); a non-numeric value cannot be turned into 'col = col - amount' SQL, so it throws with the offending column name in the message.","triggerScenarios":"->decrementEach(['stock' => 'abc', 'reserved' => 1]), or any map where at least one value is non-numeric.","commonSituations":"Bulk-decrementing from a request payload without casting; mixing numeric and string metrics; refactoring single-column decrement() into a map and dropping a value.","solutions":["Cast each amount when building the map: ['stock' => (int) $req->stock].","Filter the input to keep only numeric entries before calling decrementEach().","Validate the payload shape at the controller layer."],"exampleFix":"// before\n->decrementEach($request->adjustments)  // ['stock' => 'two']\n\n// after\n$dec = array_map(fn ($v) => (float) $v, $request->adjustments);\n->decrementEach($dec)","handlingStrategy":"validation","validationCode":"foreach ($columns as $col => $amt) {\n    if (! is_numeric($amt)) {\n        throw new InvalidArgumentException(\"{$col} must be numeric.\");\n    }\n}\n$query->decrementEach($columns);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cast amounts when building the map: ['stock' => (int) $req->stock].","Filter inputs to numeric values before decrementEach().","Use form requests with 'numeric' rules for adjustment payloads."],"tags":["query-builder","decrement","database","types"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}