diff --git a/src/Illuminate/Http/Client/Batch.php b/src/Illuminate/Http/Client/Batch.php index a25bb7685384..5d54e8899d09 100644 --- a/src/Illuminate/Http/Client/Batch.php +++ b/src/Illuminate/Http/Client/Batch.php @@ -290,6 +290,14 @@ 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 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); + }); + if (! $this->hasFailures() && $this->thenCallback !== null) { call_user_func($this->thenCallback, $this, $results); }