laravel/framework · error · InvalidArgumentException

Non-numeric value passed to decrement method.

Error message

Non-numeric value passed to decrement method.

What it means

Thrown by decrement when $amount fails is_numeric(). decrement mirrors increment: it generates `SET col = col - amount` and requires the amount to be numeric. Default is 1, so the error only appears when a caller explicitly passes a non-numeric value (null, string text, array, object).

Source

Thrown at src/Illuminate/Database/Query/Builder.php:4473

            $columns[$column] = $this->raw("{$this->grammar->wrap($column)} + $amount");
        }

        return $this->update(array_merge($columns, $extra));
    }

    /**
     * Decrement a column's value by a given amount.
     *
     * @param  string  $column
     * @param  float|int  $amount
     * @return int<0, max>
     *
     * @throws \InvalidArgumentException
     */
    public function decrement($column, $amount = 1, array $extra = [])
    {
        if (! is_numeric($amount)) {
            throw new InvalidArgumentException('Non-numeric value passed to decrement method.');
        }

        return $this->decrementEach([$column => $amount], $extra);
    }

    /**
     * Decrement the given column's values by the given amounts.
     *
     * @param  array<string, float|int|numeric-string>  $columns
     * @param  array<string, mixed>  $extra
     * @return int<0, max>
     *
     * @throws \InvalidArgumentException
     */
    public function decrementEach(array $columns, array $extra = [])
    {
        foreach ($columns as $column => $amount) {
            if (! is_numeric($amount)) {

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Validate input: `$request->validate(['qty' => 'required|numeric|min:0']);`.
  2. Cast with a default: `->decrement('stock', (float) $request->input('qty', 1))`.
  3. Reject empty/null before calling.
  4. Use request form requests to enforce numeric on the decrement amount.

Example fix

// before
$product->decrement('stock', $request->input('qty'));
// when qty is null => Non-numeric value passed to decrement method.

// after
$request->validate(['qty' => 'required|numeric|min:0']);
$product->decrement('stock', (float) $request->qty);
Defensive patterns

Strategy: validation

Validate before calling

if (! is_numeric($amount)) {
    throw new \InvalidArgumentException('decrement amount must be numeric, got: '.get_debug_type($amount));
}
$model->decrement($column, (float) $amount);

Type guard

function isNumericAmount(mixed $amount): bool
{
    return is_int($amount) || is_float($amount) || (is_string($amount) && is_numeric($amount));
}

Try / catch

// Validate the amount before calling; catching is rarely useful for a programming/type error.

Prevention

When it happens

Trigger: `->decrement('stock', $request->qty)` when qty is null or a non-numeric string. Passing a value read from a nullable column back as the decrement amount. Negative strings like '-3' are numeric and accepted.

Common situations: Cart/inventory decrement endpoints receiving unvalidated JSON; counters fed by user input; converting a manual `update(['stock' => DB::raw('stock - '.$n)])` where $n is tainted.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/92318cf58349f7f5.json. Report an issue: GitHub.