Skip to content

Commit

Permalink
Added setVisible and setHidden into Model\Collection. (#7147)
Browse files Browse the repository at this point in the history
  • Loading branch information
People-Sea authored Nov 11, 2024
1 parent 32cd929 commit 6632bbd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Model/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,22 @@ public function makeVisible($attributes)
return $this->each->makeVisible($attributes);
}

/**
* Set the visible attributes across the entire collection.
*/
public function setVisible(array $visible): static
{
return $this->each->setVisible($visible);
}

/**
* Set the hidden attributes across the entire collection.
*/
public function setHidden(array $hidden): static
{
return $this->each->setHidden($hidden);
}

/**
* Append an attribute across the entire collection.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/ModelCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,22 @@ public function testMakeHiddenAddsHiddenOnEntireCollection()
$this->assertEquals(['hidden', 'visible'], $c[0]->getHidden());
}

public function testSetVisibleReplacesVisibleOnEntireCollection()
{
$c = new Collection([new TestEloquentCollectionModel()]);
$c = $c->setVisible(['hidden']);

$this->assertEquals(['hidden'], $c[0]->getVisible());
}

public function testSetHiddenReplacesHiddenOnEntireCollection()
{
$c = new Collection([new TestEloquentCollectionModel()]);
$c = $c->setHidden(['visible']);

$this->assertEquals(['visible'], $c[0]->getHidden());
}

public function testMakeVisibleRemovesHiddenFromEntireCollection()
{
$c = new Collection([new TestEloquentCollectionModel()]);
Expand Down

0 comments on commit 6632bbd

Please sign in to comment.