Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
Fix increment & decrement bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jan 29, 2018
1 parent 318a1ab commit 25d9c54
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Traits/HasRevaluableAttributes.php
Expand Up @@ -190,6 +190,35 @@ public function setAttribute($attribute, $value)
return parent::setAttribute($attribute, $value);
}

/**
* Run the increment or decrement method on the model.
*
* @param string $column
* @param int $amount
* @param array $extra
* @param string $method
* @return int
*/
protected function incrementOrDecrement($column, $amount, $extra, $method)
{
$query = $this->newQuery();

if (! $this->exists) {
return $query->{$method}($column, $amount, $extra);
}

$this->incrementOrDecrementAttributeValue($column, $amount, $extra, $method);

// ***[ fix increment/decrement bug]***
if ($valuator = $this->getAttributeValuator($column)) {
$amount = forward_static_call([$valuator, 'toStorableValue'], $amount);
}

return $query->where(
$this->getKeyName(), $this->getKey()
)->{$method}($column, $amount, $extra);
}

/**
* Override HasAttributes::attributesToArray.
*
Expand Down

0 comments on commit 25d9c54

Please sign in to comment.