From a3ce4517f3e7cdd294bd3da528208c5871ae7ba2 Mon Sep 17 00:00:00 2001 From: Philipp Daun Date: Sun, 10 Nov 2024 19:34:06 +0100 Subject: [PATCH 1/2] Accept collections in ampersand list modifier --- src/Modifiers/CoreModifiers.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Modifiers/CoreModifiers.php b/src/Modifiers/CoreModifiers.php index 4cb681806b..0d3b1a8d0a 100644 --- a/src/Modifiers/CoreModifiers.php +++ b/src/Modifiers/CoreModifiers.php @@ -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; } From 2869c1c3b34af2ae0a9a8819d495eefd41f71706 Mon Sep 17 00:00:00 2001 From: Philipp Daun Date: Sun, 10 Nov 2024 19:34:33 +0100 Subject: [PATCH 2/2] Add test for collections in ampersand modifier --- tests/Modifiers/AmbersandListTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Modifiers/AmbersandListTest.php b/tests/Modifiers/AmbersandListTest.php index d32eb5338c..7d54f91a51 100644 --- a/tests/Modifiers/AmbersandListTest.php +++ b/tests/Modifiers/AmbersandListTest.php @@ -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 {