mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Added setVisible
and setHidden
into Model\Collection
. (#7147)
This commit is contained in:
parent
70fc945dec
commit
2788a2f069
@ -4,6 +4,7 @@
|
||||
|
||||
- [#7141](https://github.com/hyperf/hyperf/pull/7141) Added method `Hyperf\Collection\Arr::shuffleAssoc`.
|
||||
- [#7143](https://github.com/hyperf/hyperf/pull/7143) Added method `Hyperf\Database\Model\Builder::findOr`.
|
||||
- [#7147](https://github.com/hyperf/hyperf/pull/7147) Added `setVisible` and `setHidden` into `Model\Collection`.
|
||||
|
||||
## Fixed
|
||||
|
||||
|
@ -521,6 +521,22 @@ class Collection extends BaseCollection implements CompressInterface
|
||||
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.
|
||||
*
|
||||
|
@ -456,6 +456,22 @@ class ModelCollectionTest extends TestCase
|
||||
$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()]);
|
||||
|
Loading…
Reference in New Issue
Block a user