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.x] Accept collections in ampersand list modifier #11102

Merged
merged 2 commits into from
Nov 11, 2024
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
4 changes: 4 additions & 0 deletions src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function addSlashes($value)
*/
public function ampersandList($value, $params)
{
if ($value instanceof Collection) {
$value = $value->all();
}

if (! is_array($value)) {
return $value;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Modifiers/AmbersandListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public function it_creates_an_list_with_default_glue(): void
$this->assertEquals('apples, bananas & jerky', $modified);
}

#[Test]
public function it_creates_an_list_from_collection(): void
{
$modified = $this->modify(collect([
'apples',
'bananas',
'jerky',
]));
$this->assertEquals('apples, bananas & jerky', $modified);
}

#[Test]
public function it_creates_an_list_with_custom_glue(): void
{
Expand Down
Loading