3
This commit is contained in:
@@ -88,6 +88,73 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $column
|
||||||
|
* @param int $value
|
||||||
|
* @return ActiveRecord|false
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function increment(string $column, int $value)
|
||||||
|
{
|
||||||
|
if (!$this->mathematics(self::INCR, [$column => $value])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->{$column} += $value;
|
||||||
|
return $this->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $column
|
||||||
|
* @param int $value
|
||||||
|
* @return ActiveRecord|false
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function decrement(string $column, int $value)
|
||||||
|
{
|
||||||
|
if (!$this->mathematics(self::DECR, [$column => $value])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->{$column} -= $value;
|
||||||
|
return $this->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $columns
|
||||||
|
* @return ActiveRecord|false
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function increments(array $columns)
|
||||||
|
{
|
||||||
|
if (!$this->mathematics(self::INCR, $columns)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach ($columns as $key => $attribute) {
|
||||||
|
$this->$key += $attribute;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $columns
|
||||||
|
* @return ActiveRecord|false
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function decrements(array $columns)
|
||||||
|
{
|
||||||
|
if (!$this->mathematics(self::DECR, $columns)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach ($columns as $key => $attribute) {
|
||||||
|
$this->$key -= $attribute;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @return bool|self
|
* @return bool|self
|
||||||
|
|||||||
Reference in New Issue
Block a user