Am trying to save some data to an API which but I keep getting this error count(): Parameter must be an array or an object that implements Countable at LINE 428,,, the API am posting data to accepts an array of objects but in my data children variable is throwing the above error..
Please assist?
$children = '[{"child_name" => "Mmansa" , "child_dob" => "jdhjdhjd" }]';
$data = [
'quote_id' => $quote,
'country_residence' => $resd,
'physical_address' => $physical,
'children' => $children,
];
Post via Curl
$res = $this->global_Curl($data, 'api/travel/save-policy-meta');
Curl function
public function global_Curl($data, $url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, (env('API_ENDPOINT_NGINX_IP') . '/' . $url));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
$response = json_decode(curl_exec($ch));
curl_close($ch);
return $response;
}
Data required by the API
{
"quote_id":136,
"country_residence":"Japan",
"physical_address":"Tokyo",
"children":[
{"child_name":"abc","child_dob":"23-05-2015"}
]
}