Skip to content

Commit

Permalink
Only check if the model contains any changes if no argument was provided
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Oct 6, 2023
1 parent 355453a commit d0ff61a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Models/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ public function discardChanges(): static
*/
public function wasChanged(array|string $attributes = null): bool
{
if (empty($attributes)) {
if (func_num_args() === 0) {
return count($this->changes) > 0;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Models/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,12 @@ public function test_changed_attributes()

$model->syncChanges();

$this->assertFalse($model->wasChanged(''));
$this->assertFalse($model->wasChanged([]));
$this->assertFalse($model->wasChanged('foo'));
$this->assertFalse($model->wasChanged(['foo']));

$this->assertTrue($model->wasChanged());
$this->assertTrue($model->wasChanged([]));
$this->assertTrue($model->wasChanged('bar'));
$this->assertTrue($model->wasChanged('baz'));
$this->assertTrue($model->wasChanged(['bar', 'baz']));
Expand Down

0 comments on commit d0ff61a

Please sign in to comment.