Skip to content

Commit 34218a1

Browse files
authored
Added Hyperf\Database\Model\Model::hasAppended(). (#7262)
1 parent 19cc230 commit 34218a1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Model/Concerns/HasAttributes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,14 @@ public function setAppends(array $appends): static
687687
return $this;
688688
}
689689

690+
/**
691+
* Return whether the accessor attribute has been appended.
692+
*/
693+
public function hasAppended(string $attribute): bool
694+
{
695+
return in_array($attribute, $this->appends);
696+
}
697+
690698
/**
691699
* Get the mutated attributes for a given instance.
692700
*/

tests/ModelTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,11 @@ public function testAppendingOfAttributes()
15161516
$this->assertEquals('camelCased', $model->camelCased);
15171517
$this->assertEquals('StudlyCased', $model->StudlyCased);
15181518

1519+
$this->assertTrue($model->hasAppended('is_admin'));
1520+
$this->assertTrue($model->hasAppended('camelCased'));
1521+
$this->assertTrue($model->hasAppended('StudlyCased'));
1522+
$this->assertFalse($model->hasAppended('not_appended'));
1523+
15191524
$model->setHidden(['is_admin', 'camelCased', 'StudlyCased']);
15201525
$this->assertEquals([], $model->toArray());
15211526

0 commit comments

Comments
 (0)