From 0cfad7e8dc0ddfa7ea766c1c7fbc615b4a827cee Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 22 Oct 2025 14:51:15 +1000 Subject: [PATCH 1/2] Ensure HTTP Batch results are returned in the same order as requested --- src/Illuminate/Http/Client/Batch.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Illuminate/Http/Client/Batch.php b/src/Illuminate/Http/Client/Batch.php index a25bb7685384..ed334bb51238 100644 --- a/src/Illuminate/Http/Client/Batch.php +++ b/src/Illuminate/Http/Client/Batch.php @@ -290,6 +290,13 @@ public function send(): array ]))->promise()->wait(); } + // Before returning the results, we must ensure that the results are sorted + // in the same order as the requests were defined, respecting any custom + // key names that were assigned to the request using the "as" method. + uksort($results, function ($key1, $key2) { + return array_search($key1, array_keys($this->requests), true) <=> array_search($key2, array_keys($this->requests), true); + }); + if (! $this->hasFailures() && $this->thenCallback !== null) { call_user_func($this->thenCallback, $this, $results); } From 3f29f2bff2b5a4f266962950d3fb5146f211d676 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Oct 2025 14:31:54 -0500 Subject: [PATCH 2/2] Update Batch.php --- src/Illuminate/Http/Client/Batch.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Http/Client/Batch.php b/src/Illuminate/Http/Client/Batch.php index ed334bb51238..5d54e8899d09 100644 --- a/src/Illuminate/Http/Client/Batch.php +++ b/src/Illuminate/Http/Client/Batch.php @@ -292,9 +292,10 @@ public function send(): array // Before returning the results, we must ensure that the results are sorted // in the same order as the requests were defined, respecting any custom - // key names that were assigned to the request using the "as" method. + // key names that were assigned to this request using the "as" method. uksort($results, function ($key1, $key2) { - return array_search($key1, array_keys($this->requests), true) <=> array_search($key2, array_keys($this->requests), true); + return array_search($key1, array_keys($this->requests), true) <=> + array_search($key2, array_keys($this->requests), true); }); if (! $this->hasFailures() && $this->thenCallback !== null) {