Skip to content

Commit

Permalink
[9.x] Add Model getAppends() (#44180)
Browse files Browse the repository at this point in the history
* Add public method getAppends()

Useful for custom model mappings.

* Add test

* Update test

* Update HasAttributes.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
artrz and taylorotwell authored Sep 17, 2022
1 parent b898924 commit 3bbc0e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,16 @@ public function append($attributes)
return $this;
}

/**
* Get the accessors that are being appended to model arrays.
*
* @return array
*/
public function getAppends()
{
return $this->appends;
}

/**
* Set the accessors to append to model arrays.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,8 @@ public function testAppendingOfAttributes()
$this->assertSame('camelCased', $model->camelCased);
$this->assertSame('StudlyCased', $model->StudlyCased);

$this->assertEquals(['is_admin', 'camelCased', 'StudlyCased'], $model->getAppends());

$this->assertTrue($model->hasAppended('is_admin'));
$this->assertTrue($model->hasAppended('camelCased'));
$this->assertTrue($model->hasAppended('StudlyCased'));
Expand Down

0 comments on commit 3bbc0e7

Please sign in to comment.