{"record":{"id":"92318cf58349f7f5","repo":"laravel/framework","slug":"non-numeric-value-passed-to-decrement-method","errorCode":null,"errorMessage":"Non-numeric value passed to decrement method.","messagePattern":"Non-numeric value passed to decrement method\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Builder.php","lineNumber":4473,"sourceCode":"            $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 = [])\n    {\n        if (! is_numeric($amount)) {\n            throw new InvalidArgumentException('Non-numeric value passed to decrement method.');\n        }\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)) {","sourceCodeStart":4455,"sourceCodeEnd":4491,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Builder.php#L4455-L4491","documentation":"decrement() mirrors increment(): it produces 'col = col - amount' SQL and therefore requires a numeric amount. A non-numeric value is rejected up front before delegating to decrementEach().","triggerScenarios":"->decrement('stock', 'abc'), ->decrement('stock', null), or passing unvalidated request input that resolves to a non-numeric string.","commonSituations":"Passing user input without casting; null from optional fields; string values that are not cleanly numeric.","solutions":["Cast the amount: ->decrement('stock', (float) $amount).","Guard with is_numeric() before calling.","Omit the amount to use the default of 1."],"exampleFix":"// before\n->decrement('stock', $request->qty)  // 'qty' = 'one'\n\n// after\n->decrement('stock', (float) $request->qty)","handlingStrategy":"validation","validationCode":"if (! is_numeric($amount)) {\n    throw new InvalidArgumentException('decrement amount must be numeric.');\n}\n$query->decrement($column, (float) $amount);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cast request input to int/float before decrement().","Omit the amount argument for the default -1.","Add a form-request rule: 'qty' => 'sometimes|numeric'."],"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"}