added decrement method to query builder.
This commit is contained in:
parent
559785f168
commit
9bf978abcd
|
@ -590,7 +590,32 @@ public function insert_get_id($values, $sequence = null)
|
|||
*/
|
||||
public function increment($column, $amount = 1)
|
||||
{
|
||||
return $this->update(array($column => Manager::raw($this->grammar->wrap($column).' + '.$amount)));
|
||||
return $this->adjust($column, $amount, ' + ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the value of a column by a given amount.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($column, $amount = 1)
|
||||
{
|
||||
return $this->adjust($column, $amount, ' - ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the value of a column up or down by a given amount.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $amount
|
||||
* @param string $operator
|
||||
* @return int
|
||||
*/
|
||||
protected function adjust($column, $amount, $operator)
|
||||
{
|
||||
return $this->update(array($column => Manager::raw($this->grammar->wrap($column).$operator.$amount)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue