From 9bf978abcd100d79b8c630cfab1103e70c53db8f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 12 Oct 2011 21:32:06 -0500 Subject: [PATCH] added decrement method to query builder. --- laravel/database/query.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/laravel/database/query.php b/laravel/database/query.php index 003cb317..df84de47 100644 --- a/laravel/database/query.php +++ b/laravel/database/query.php @@ -590,7 +590,32 @@ class Query { */ 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))); } /**