Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Add makeHidden method to the Eloquent collection class #13152

Merged
merged 1 commit into from
Apr 14, 2016
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
17 changes: 14 additions & 3 deletions src/Illuminate/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ public function except($keys)
return new static(array_values($dictionary));
}

/**
* Make the given, typically visible, attributes hidden across the entire collection.
*
* @param array|string $attributes
* @return $this
*/
public function makeHidden($attributes)
{
return $this->each(function ($model) use ($attributes) {
$model->addHidden($attributes);
});
}

/**
* Make the given, typically hidden, attributes visible across the entire collection.
*
Expand All @@ -204,11 +217,9 @@ public function except($keys)
*/
public function makeVisible($attributes)
{
$this->each(function ($model) use ($attributes) {
return $this->each(function ($model) use ($attributes) {
$model->makeVisible($attributes);
});

return $this;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion tests/Database/DatabaseEloquentCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,15 @@ public function testExceptReturnsCollectionWithoutGivenModelKeys()
$this->assertEquals(new Collection([$one]), $c->except([2, 3]));
}

public function testWithHiddenSetsHiddenOnEntireCollection()
public function testMakeHiddenAddsHiddenOnEntireCollection()
{
$c = new Collection([new TestEloquentCollectionModel]);
$c = $c->makeHidden(['visible']);

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

public function testMakeVisibleRemovesHiddenFromEntireCollection()
{
$c = new Collection([new TestEloquentCollectionModel]);
$c = $c->makeVisible(['hidden']);
Expand Down