[英]Why my second call on url doesn't work (Laravel,Guzzle)?
這是我調用2個api的函數,首先從中獲取第二個URL中使用的client_id。 問題是,在我調用第二個URL之后,我的頁面正在加載而沒有結束。
public function getDevices(){
$route='http://localhost:8000/api/devices';
$device= new Client();
$answer= $device->request('GET', $route);
$body = $answer->getBody();
$status = 'true';
$message = 'Data found!';
$final= json_decode($body);
$id_array = array();
foreach ($finalas $item) {
// Add each id value in your array
$id_array[]= $item->clientId;
}
foreach($id_array as $my_id) {
$answer2= $client->request('GET', 'http://localhost:8080/api/devices/deviceAvailability/' . $my_id );
$body2 = $response2->getBody();
$final2= json_decode($body2);
}
return view('new.home', ['clients' => $final, 'status'=> $final2]);
我認為
return view('new.home', ['clients' => $final, 'status'=> $final2])
是錯的。 因為$final
被解碼變量,也許$final
包含幾種類型的變量。
在php中,您無法設置包含幾種類型的變量的參數。
請那樣做。
return view('new.home', ['clients' => $body, 'status'=> $final2]);
那是因為json編碼的變量只是一個字符串。
我想要你的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.