Quiero enviar una solicitud con la fachada Http en Laravel, pero no puedo pasar los datos del objeto json, debe ser solo una matriz.
Http::withHeaders(['Content-Type' => 'application/json'])->withOptions(['headers' => $coockie])->post($this->policy_url . $address, json_encode($data));El valor de mi variable de datos:
$data = [ "document" => [ "customerId" => 1, "currencyId" => 1, "settlementPolicyId" => 8, "storeId" => 16, "documentPatternId" => 2, "items" => [ [ "productId" => 193, "unitId" => 2, "quantity" => 1, "storeId" => 16, "TrackingFactor1" => "1214", "PartTrackingFactorRef1" => 1053, "TrackingFactorHasQuantity1" => true, "TrackingFactorValue" => "test", "fee" => 0 ] ] ], "payments" => [ [ "key" => "Cash", "amount" => 445810, "attr" => [] ] ] ];El error:
TypeError Argument 2 passed to Illuminate\Http\Client\PendingRequest::post() must be of the type array, string givenHaz json_encode($data) antes de enviarlo a la solicitud.
$myArray = json_encode($data); $finalData = explode(' ',$myArray);