Illuminate\Database\Query\Builder::increment PHP Method

increment() public method

Increment a column's value by a given amount.
public increment ( string $column, integer $amount = 1, array $extra = [] ) : integer
$column string
$amount integer
$extra array
return integer
    public function increment($column, $amount = 1, array $extra = [])
    {
        if (!is_numeric($amount)) {
            throw new InvalidArgumentException('Non-numeric value passed to increment method.');
        }
        $wrapped = $this->grammar->wrap($column);
        $columns = array_merge([$column => $this->raw("{$wrapped} + {$amount}")], $extra);
        return $this->update($columns);
    }

Usage Example

Example #1
0
 /**
  * Increment a column's value by a given amount.
  *
  * @param  string  $column
  * @param  int     $amount
  * @param  array   $extra
  * @return int
  */
 public function increment($column, $amount = 1, array $extra = array())
 {
     $extra = $this->addUpdatedAtColumn($extra);
     return $this->query->increment($column, $amount, $extra);
 }