Skip to content

Commit

Permalink
Merge branch 'fix-increment-attribute' of https://github.com/xcaptain…
Browse files Browse the repository at this point in the history
…/framework into xcaptain-fix-increment-attribute
  • Loading branch information
taylorotwell committed Apr 10, 2017
2 parents 6c5f3a4 + ac2d8fc commit a3e1acc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ protected function incrementOrDecrement($column, $amount, $extra, $method)
return $query->{$method}($column, $amount, $extra);
}

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

return $query->where(
$this->getKeyName(), $this->getKey()
Expand All @@ -425,9 +425,10 @@ protected function incrementOrDecrement($column, $amount, $extra, $method)
* @param string $method
* @return void
*/
protected function incrementOrDecrementAttributeValue($column, $amount, $method)
protected function incrementOrDecrementAttributeValue($column, $amount, $method, $extra = [])
{
$this->{$column} = $this->{$column} + ($method == 'increment' ? $amount : $amount * -1);
$this->fill($extra);

$this->syncOriginalAttribute($column);
}
Expand Down
13 changes: 8 additions & 5 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,13 @@ public function testIncrementOnExistingModelCallsQueryAndSetsAttribute()
$query->shouldReceive('where')->andReturn($query);
$query->shouldReceive('increment');

$model->publicIncrement('foo');

$this->assertEquals(3, $model->foo);
$model->publicIncrement('foo', 1);
$this->assertFalse($model->isDirty());

$model->publicIncrement('foo', 1, ['category' => 1]);
$this->assertEquals(4, $model->foo);
$this->assertEquals(1, $model->category);
$this->assertTrue($model->isDirty('category'));
}

public function testRelationshipTouchOwnersIsPropagated()
Expand Down Expand Up @@ -1651,9 +1654,9 @@ public function setPasswordAttribute($value)
$this->attributes['password_hash'] = sha1($value);
}

public function publicIncrement($column, $amount = 1)
public function publicIncrement($column, $amount = 1, $extra = [])
{
return $this->increment($column, $amount);
return $this->increment($column, $amount, $extra);
}

public function belongsToStub()
Expand Down

0 comments on commit a3e1acc

Please sign in to comment.