I have a REST API that should save the contents of a json into a mysql database however it’s inserting everything as null? However its weird because whenever the json is sent from the swift sdk it works just fine.
public function saveTracking($request, $response, $args) {
if(!$this->validToken($response)) {
return $response;
}
$data = $request->getParsedBody();
$tracking_data = json_decode(json_encode($data['tracking']), FALSE);
$total_records = 0;
//error_log(print_r($tracking_data, true));
foreach($tracking_data as $key => $value) {
$tracking = new EstablishmentTracking();
$tracking->mobile_user_id = $this->authUser->id;
$tracking->report_date = $value->report_date;
$tracking->establishment_id = $value->establishment_id;
if ($value->platform == MobileUser::ANDROID || $value->platform == MobileUser::IOS) {
$tracking->platform = $value->platform;
}
$tracking->purchase_id = $value->purchase_id;
error_log(print_r($tracking, true));
$this->establishmentService->saveEstablishmentTracking($tracking);
$total_records++;
}
$arr = array("status" => "ok"
,"total_records" => $total_records
);
print_r($arr);
$newResponse = $response->withJson($arr);
return $newResponse;
}
After adding a line that prints the contesnts of the variable, i got the following:
stdClass Object
(
[establishment_id] => 39
[report_date] => 2018-05-31 18:45:05
[platform] => android
[purchase_id] => 0
Is it not sending the json correctly as an array? or what seems to be the issue.