为什么我第二次调用url不起作用(Laravel,Guzzle)? [英] Why my second call on url doesn't work (Laravel,Guzzle)?

查看:42
本文介绍了为什么我第二次调用url不起作用(Laravel,Guzzle)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个我调用2个api的函数,从第一个我得到第二个URL中使用的client_id.问题是,在我调用第二个URL之后,我的页面正在加载而没有结束.

This is a function where i call 2 api, from first i get client_id which i used in second url. Problem is that after i call second url my page is loading without end.

页面图像

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可能包含几种类型的变量.

is wrong. Because $final is decoded variable, maybe $final contains several types of variables.

在php中,您无法设置包含多种类型的变量的参数.

In php, you can not set parameter that contains several types of variables.

请这样做.

return view('new.home', ['clients' => $body, 'status'=> $final2]);

那是因为json编码的变量只是一个字符串.

That's because json encoded variable is only a string.

我想要你的结果.

这篇关于为什么我第二次调用url不起作用(Laravel,Guzzle)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆