{"record":{"id":"0afc7c0534620984","repo":"laravel/framework","slug":"non-numeric-value-passed-to-increment-method","errorCode":null,"errorMessage":"Non-numeric value passed to increment method.","messagePattern":"Non-numeric value passed to increment method\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Builder.php","lineNumber":4431,"sourceCode":"        return $this->connection->affectingStatement(\n            $this->grammar->compileUpsert($this, $values, (array) $uniqueBy, $update),\n            $bindings\n        );\n    }\n\n    /**\n     * Increment 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 increment($column, $amount = 1, array $extra = [])\n    {\n        if (! is_numeric($amount)) {\n            throw new InvalidArgumentException('Non-numeric value passed to increment method.');\n        }\n\n        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)) {","sourceCodeStart":4413,"sourceCodeEnd":4449,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Builder.php#L4413-L4449","documentation":"increment() is meant to add a numeric delta to a column via 'col = col + amount'. A non-numeric amount (string, null, object) cannot be safely interpolated into the SQL expression, so the method rejects it up front with InvalidArgumentException before delegating to incrementEach().","triggerScenarios":"->increment('views', 'abc'), ->increment('views', null), ->increment('views', $userInput) where $userInput is a non-numeric string.","commonSituations":"Passing request input without casting; null from optional fields; string values that look numeric but include whitespace or units; mis-typed arguments from refactoring.","solutions":["Cast the amount explicitly: ->increment('views', (float) $amount).","Validate the input is_numeric() before calling.","Default to 1 (the built-in default) when no amount is supplied."],"exampleFix":"// before\n->increment('views', $request->step)  // 'step' = 'two'\n\n// after\n->increment('views', (float) $request->step)","handlingStrategy":"validation","validationCode":"if (! is_numeric($amount)) {\n    throw new InvalidArgumentException('increment amount must be numeric.');\n}\n$query->increment($column, (float) $amount);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cast request input to int/float before increment().","Omit the amount argument when you want the default +1.","Add a form-request rule: 'step' => 'sometimes|numeric'."],"tags":["query-builder","increment","database","types"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}