Skip to content

Commit 6632bbd

Browse files
authored
Added setVisible and setHidden into Model\Collection. (#7147)
1 parent 32cd929 commit 6632bbd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Model/Collection.php

+16
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,22 @@ public function makeVisible($attributes)
521521
return $this->each->makeVisible($attributes);
522522
}
523523

524+
/**
525+
* Set the visible attributes across the entire collection.
526+
*/
527+
public function setVisible(array $visible): static
528+
{
529+
return $this->each->setVisible($visible);
530+
}
531+
532+
/**
533+
* Set the hidden attributes across the entire collection.
534+
*/
535+
public function setHidden(array $hidden): static
536+
{
537+
return $this->each->setHidden($hidden);
538+
}
539+
524540
/**
525541
* Append an attribute across the entire collection.
526542
*

tests/ModelCollectionTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,22 @@ public function testMakeHiddenAddsHiddenOnEntireCollection()
456456
$this->assertEquals(['hidden', 'visible'], $c[0]->getHidden());
457457
}
458458

459+
public function testSetVisibleReplacesVisibleOnEntireCollection()
460+
{
461+
$c = new Collection([new TestEloquentCollectionModel()]);
462+
$c = $c->setVisible(['hidden']);
463+
464+
$this->assertEquals(['hidden'], $c[0]->getVisible());
465+
}
466+
467+
public function testSetHiddenReplacesHiddenOnEntireCollection()
468+
{
469+
$c = new Collection([new TestEloquentCollectionModel()]);
470+
$c = $c->setHidden(['visible']);
471+
472+
$this->assertEquals(['visible'], $c[0]->getHidden());
473+
}
474+
459475
public function testMakeVisibleRemovesHiddenFromEntireCollection()
460476
{
461477
$c = new Collection([new TestEloquentCollectionModel()]);

0 commit comments

Comments
 (0)