【发布时间】:2022-01-01 01:00:30
【问题描述】:
我正在开发一个 laravel 项目,我需要在其中显示来自 API 的列表和统计信息。对于统计信息和内容列表,有单独的 URL。而且我必须将两者都显示在一个页面上。
如何在一个页面上调用多个 API URL? 假设 https://localhost/api/games 和 https://localhost/api/stats 是两个 URL。
我正在使用 Laravel 版本 7 PHP版本 7.2.3
这里是控制器:
public function index()
{
$collection = Http::withHeaders([
'x-api-host' => $host,
'x-api-key' => $key
])->get('https://localhost/api/games');
return view('welcome', ['collection'=>$collection]);
}
【问题讨论】:
-
不确定问题到底出在哪里,只需创建第二个对
https://localhost/api/stats的 HTTP 调用,命名它,例如$collectionStats
标签: php laravel api laravel-http-client