From 5eaf080d6030f805ca9f64a4dcef9acad8553f81 Mon Sep 17 00:00:00 2001 From: benatoff <146389211+benatoff@users.noreply.github.com> Date: Tue, 21 Jan 2025 16:55:17 +0100 Subject: [PATCH 1/3] fix: collapseWithKeys on empty collection --- src/Illuminate/Collections/Collection.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index 71b432cef89c..f6049d630767 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -148,6 +148,10 @@ public function collapse() */ public function collapseWithKeys() { + if(! $this->items){ + return $this; + } + $results = []; foreach ($this->items as $key => $values) { From d60b375a247bf689376cf685b6466c7b5ad3320e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jan 2025 10:12:12 -0600 Subject: [PATCH 2/3] Update Collection.php --- src/Illuminate/Collections/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index f6049d630767..463a9fc27621 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -148,7 +148,7 @@ public function collapse() */ public function collapseWithKeys() { - if(! $this->items){ + if (! $this->items) { return $this; } From d97e308129f8fc9ce0bc9c517585e93b6100b7eb Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jan 2025 10:12:33 -0600 Subject: [PATCH 3/3] Update Collection.php --- src/Illuminate/Collections/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index 463a9fc27621..9b95b18f949d 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -149,7 +149,7 @@ public function collapse() public function collapseWithKeys() { if (! $this->items) { - return $this; + return new static; } $results = [];