0

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" => []
 ]
 ]
 ]

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.