Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Illuminate/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,28 @@ public function makeVisible($attributes)
return $this->each->makeVisible($attributes);
}

/**
* Merge the given, typically visible, attributes hidden across the entire collection.
*
* @param array<array-key, string>|string $attributes
* @return $this
*/
public function mergeHidden($attributes)
{
return $this->each->mergeHidden($attributes);
}

/**
* Merge the given, typically hidden, attributes visible across the entire collection.
*
* @param array<array-key, string>|string $attributes
* @return $this
*/
public function mergeVisible($attributes)
{
return $this->each->mergeVisible($attributes);
}

/**
* Set the visible attributes across the entire collection.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/Database/DatabaseEloquentCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,22 @@ public function testMakeVisibleRemovesHiddenFromEntireCollection()
$this->assertEquals([], $c[0]->getHidden());
}

public function testMergeHiddenAddsHiddenOnEntireCollection()
{
$c = new Collection([new TestEloquentCollectionModel]);
$c = $c->mergeHidden(['merged']);

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

public function testMergeVisibleRemovesHiddenFromEntireCollection()
{
$c = new Collection([new TestEloquentCollectionModel]);
$c = $c->mergeVisible(['merged']);

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

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