{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Query/Builder.php#L4432-L4468","documentation":"Thrown by incrementEach when one of the per-column amounts fails is_numeric(). Unlike increment (single value), incrementEach takes an associative array of column => amount and validates each entry individually, naming the offending column in the message so you can locate the bad input.","triggerScenarios":"`incrementEach(['views' => $req->views, 'score' => 'high'])` where 'high' is a non-numeric string. Building the amounts map from request input without numeric validation. Mixing a numeric column with a free-text field in one call.","commonSituations":"Batch counter APIs; admin tooling that increments several stats at once from a form; converting individual increment() calls into incrementEach() and inheriting unvalidated inputs.","solutions":["Validate all amounts before the call: `$data = $request->validate(['*.amount' => 'numeric']);`.","Cast each value: `array_map(fn($v) => is_numeric($v) ? $v + 0 : 0, $amounts)`.","Inspect the named column in the error to locate the offending key in your input map.","Decouple free-text fields from the increment map."],"exampleFix":"// before\n$model->incrementEach([\n    'views' => $request->views,\n    'score' => $request->score, // 'high'\n]);\n// => Non-numeric value passed as increment amount for column: 'score'.\n\n// after\n$amounts = collect(['views','score'])\n    ->mapWithKeys(fn ($c) => [$c => (float) $request->input($c, 0)])\n    ->toArray();\n$model->incrementEach($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->incrementEach($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 incrementEach; the error names the column to fix.","preventionTips":["Validate batch adjustment inputs with array.* numeric rules.","Cast each value with a default before building the map.","Use the column name in the error to locate the offending input field."],"tags":["query-builder","increment","numeric","invalid-argument"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}