laravel/framework · error · InvalidArgumentException

Non-numeric value passed to increment method.

Error message

Non-numeric value passed to increment method.

What it means

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().

Solutions

  1. Cast the amount explicitly: ->increment('views', (float) $amount).
  2. Validate the input is_numeric() before calling.
  3. Default to 1 (the built-in default) when no amount is supplied.

Example fix

// before
->increment('views', $request->step)  // 'step' = 'two'

// after
->increment('views', (float) $request->step)
Defensive patterns

Strategy: validation

Validate before calling

if (! is_numeric($amount)) {
    throw new InvalidArgumentException('increment amount must be numeric.');
}
$query->increment($column, (float) $amount);

Prevention

When it happens

Trigger: ->increment('views', 'abc'), ->increment('views', null), ->increment('views', $userInput) where $userInput is a non-numeric string.

Common situations: Passing request input without casting; null from optional fields; string values that look numeric but include whitespace or units; mis-typed arguments from refactoring.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/0afc7c0534620984. Report an issue: GitHub.

Appendix: source

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

        return $this->connection->affectingStatement(
            $this->grammar->compileUpsert($this, $values, (array) $uniqueBy, $update),
            $bindings
        );
    }

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

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

    /**
     * Increment 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 incrementEach(array $columns, array $extra = [])
    {
        foreach ($columns as $column => $amount) {
            if (! is_numeric($amount)) {

View on GitHub (pinned to e0f6eb3518)