diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index fc5feef0eb2a..f516d8006372 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -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|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|string $attributes + * @return $this + */ + public function mergeVisible($attributes) + { + return $this->each->mergeVisible($attributes); + } + /** * Set the visible attributes across the entire collection. * diff --git a/tests/Database/DatabaseEloquentCollectionTest.php b/tests/Database/DatabaseEloquentCollectionTest.php index 872a01a72ee0..ca0f980c1e6c 100755 --- a/tests/Database/DatabaseEloquentCollectionTest.php +++ b/tests/Database/DatabaseEloquentCollectionTest.php @@ -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]);