{"record":{"id":"3baef3783287af5e","repo":"laravel/framework","slug":"non-numeric-value-passed-as-increment-amount-for-c","errorCode":null,"errorMessage":"Non-numeric value passed as increment amount for column: '$column'.","messagePattern":"Non-numeric value passed as increment amount for column: '\\$column'\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Builder.php","lineNumber":4450,"sourceCode":"        }\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)) {\n                throw new InvalidArgumentException(\"Non-numeric value passed as increment amount for column: '$column'.\");\n            } elseif (! is_string($column)) {\n                throw new InvalidArgumentException('Non-associative array passed to incrementEach 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     * 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","sourceCodeStart":4432,"sourceCodeEnd":4468,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Builder.php#L4432-L4468","documentation":"incrementEach() 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 to make debugging easy.","triggerScenarios":"->incrementEach(['views' => 'abc', 'clicks' => 1]), or any associative array where at least one value is non-numeric.","commonSituations":"Bulk-updating counters from a request payload without casting; mixing numeric and string metrics; refactoring single-column increment() calls into a map and dropping a value.","solutions":["Cast each amount when building the map: ['views' => (int) $req->views, ...].","Filter the input to keep only numeric entries before calling incrementEach().","Validate the payload shape at the controller layer."],"exampleFix":"// before\n->incrementEach($request->counters)  // ['views' => 'two']\n\n// after\n$inc = array_map(fn ($v) => (float) $v, $request->counters);\n->incrementEach($inc)","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->incrementEach($columns);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build the map with explicit casts: ['views' => (int) $req->views].","Filter inputs to numeric values before incrementEach().","Use form requests with 'numeric' rules for counter payloads."],"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"}