Skip to content

Commit 3bbc0e7

Browse files
artrztaylorotwell
andauthored
[9.x] Add Model getAppends() (#44180)
* Add public method getAppends() Useful for custom model mappings. * Add test * Update test * Update HasAttributes.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent b898924 commit 3bbc0e7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,6 +2078,16 @@ public function append($attributes)
20782078
return $this;
20792079
}
20802080

2081+
/**
2082+
* Get the accessors that are being appended to model arrays.
2083+
*
2084+
* @return array
2085+
*/
2086+
public function getAppends()
2087+
{
2088+
return $this->appends;
2089+
}
2090+
20812091
/**
20822092
* Set the accessors to append to model arrays.
20832093
*

tests/Database/DatabaseEloquentModelTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,8 @@ public function testAppendingOfAttributes()
17981798
$this->assertSame('camelCased', $model->camelCased);
17991799
$this->assertSame('StudlyCased', $model->StudlyCased);
18001800

1801+
$this->assertEquals(['is_admin', 'camelCased', 'StudlyCased'], $model->getAppends());
1802+
18011803
$this->assertTrue($model->hasAppended('is_admin'));
18021804
$this->assertTrue($model->hasAppended('camelCased'));
18031805
$this->assertTrue($model->hasAppended('StudlyCased'));

0 commit comments

Comments
 (0)