Home > Mobile >  How to access array in side object with guzzle laravel inside blade?
How to access array in side object with guzzle laravel inside blade?

Time:08-05

i am trying to access an array inside an object with guzzle laravel

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:

{
"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:

{{ $data['DocNo'] }}

now how can i access "TL" array to display its data? 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):

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

CodePudding user response:

Sam, you need to access the data using $data['TL'][0]['Dtl']

  • Related