简体   繁体   English

如何使用刀片内部的喷嘴 laravel 访问 object 侧面的阵列?

[英]How to access array in side object with guzzle laravel inside blade?

i am trying to access an array inside an object with guzzle laravel我正在尝试使用 guzzle laravel 访问 object 内的数组

controller: controller:

$client = new Client();
    $headers = [
        'Authorization' => $token,
        'Content-Type' => 'application/x-www-form-urlencoded'
    ];
    $options = [
        'form_params' => [
            'DocNo' => $DocNo
        ]
    ];
    $request = new Psr7Request('GET', 'http://example.com/api/Order/GetOrder/', $headers);
    $res = $client->sendAsync($request, $options)->wait();
    $data = json_decode($res->getBody(),true);

    return view('api.auth.orders.show', compact('data'));

the output of the above function:上述function的output:

{
"Key": 31454,
"DocNo": "SO-000275",
"AOQty": 0.0,
"TL": [
    {
        "Dtl": 31455,
        "Code": "Screw Hex",
        "Detail": true,
        "DTL": []
    }
]
}

in the view i am able to get "Key","DocNo","AOQty" like this:在视图中,我可以像这样获得“Key”、“DocNo”、“AOQty”:

{{ $data['DocNo'] }}

now how can i access "TL" array to display its data?现在我如何访问“TL”数组来显示它的数据? i tried:我试过了:

{{ $data['TL']['Dtl'] }}

but i got this error:但我收到了这个错误:

Undefined array key "Dtl"

and tried:并尝试:

{{ $data->TL['Dtl'] }}

got this error:得到这个错误:

Attempt to read property "TL" on array

what am i doing wrong here?我在这里做错了什么?

UPDATE:更新:

results when i return "dump($data):当我返回“转储($data)时的结果:

array:41 [▼
"Key" => 31454
"DocNo" => "SO-000275"
"AOQty" => 0.0
"SODTL" => array:1 [▼
0 => array:21 [▼
  "Dtl" => 31455
  "Code" => "Screw Hex"
  "Detail" => true
  "DTL" => []
 ]
 ]
 ]

Sam, you need to access the data using $data['TL'][0]['Dtl'] Sam,您需要使用 $data['TL'][0]['Dtl'] 访问数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM