Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

webfuelcode's avatar

Multiple API call in blade

I have got this in laravel HTTP client for using multiple API URL.

use Illuminate\Http\Client\Pool;
use Illuminate\Support\Facades\Http;

$responses = Http::pool(fn (Pool $pool) => [
    $pool->get('http://localhost/first'),
    $pool->get('http://localhost/second'),
    $pool->get('http://localhost/third'),
]);

return $responses[0]->ok() &&
       $responses[1]->ok() &&
       $responses[2]->ok();

But how to use withHeaders for API host and API key. Then pass the data to the blade page...

0 likes
9 replies
Sinnbeck's avatar

Did you try just passing it to each?

$pool->get('http://localhost/first')->withHeaders($headers),

//or for all
$responses = Http::pool(fn (Pool $pool) => [
    $pool->get('http://localhost/first'),
    $pool->get('http://localhost/second'),
    $pool->get('http://localhost/third'),
])->withHeaders($headers);

And passing to blade

return view('lala', compact('responses'));
webfuelcode's avatar

@sinnbeck

$responses = Http::pool(fn (Pool $pool) => [
            $pool->get('https://localhost/firsts'),
            $pool->get('https://localhost/second'),
            $pool->get('http://localhost/third'),
        ])->withHeaders([
            'x-rapidapi-host' => $host,
            'x-rapidapi-key' => $key
        ]);

It shows error syntax error, unexpected '$pool' (T_VARIABLE), expecting ')'

webfuelcode's avatar

@Sinnbeck Ok I am using laravel 7 because I am still not good with the tailwind. Is there any way to do so using laravel 7 or I have to use laravel 8...

Sinnbeck's avatar

@webfuelcode the you cannot use short functions

$responses = Http::pool(function (Pool $pool) {
   return [
            $pool->get('https://localhost/firsts'),
            $pool->get('https://localhost/second'),
            $pool->get('http://localhost/third'),
        ];
})->withHeaders([
            'x-rapidapi-host' => $host,
            'x-rapidapi-key' => $key
        ]);

Please or to participate in this conversation.