phparrayslaravellaravel-http-client

how to access array in Post request with http client laravel


i have this function to store data from a blade form:

$store = Http::withHeaders([
        'Content-Type' => 'application/json',
        'Authorization' => $token,
    ])->post('http://example.com/api/Order/', [
        'Key' => 1167722,
        'No' => "12",
        'TL' => [
            'Dtl' => "",
            'Code' => "Screw Hex",
            'IsDetail' => true,
            "DTL" => [],
            ]
            ]);

            return $store;

and this is what the response return:

{"Key":1167722,"No":"12","TL":[]}

and nothing is saved inside TL array i tried wrapping TL array with json_encode() and still no luck and i tried

'TL[Dtl]' => 722,

and it didn't store as well


Solution

  • SOLUTION:

    'TL' => array ([
            'Dtl' => "",
            'Code' => "Screw Hex",
            'IsDetail' => true,
            "DTL" => [],
            ])
            ]);
    

    added array()