How to store API Json Response to db In Laravel Controller.
Here is the controller >>
public function diagnosisStore(Request $request)
{
$request->validate([
'symptoms' => 'required',
'gender' => 'required|string|max:50',
'dob' => 'required|min:4',
]);
$user = Auth::user();
$tokenGenerator = new Token($this->config['username'],$this->config['password'],$this->config['authServiceUrl']);
$token = $tokenGenerator->loadToken();
if (!isset($token))
exit();
$api_medic = new Apimedic($token, $this->config['healthServiceUrl'], 'en-gb');
$symptoms = $request['symptoms'];
$input = $request->all();
$selectedSymptoms = $input['symptoms'];
$gender = $input['gender'];
$dob = $input['dob'];
$input['diagnosis'] = $api_medic->loadDiagnosis($selectedSymptoms, $gender, $dob);
Diagnose::create($input);
$notify[] = ['success', 'Diagnosis initiated Successfully.'];
return back()->withNotify($notify);
}
And here is the JSON Response from the API
^ array:3 [▼
0 => array:2 [▼
"Issue" => array:7 [▼
"ID" => 86
"Name" => "Coronary heart disease"
"Accuracy" => 90
"Icd" => "I20;I21;I22;I23;I24;I25"
"IcdName" => "Angina pectoris;Acute myocardial infarction;Subsequent myocardial infarction;Certain current complications following acute myocardial infarction;Other acute isc ▶"
"ProfName" => "Coronary artery disease"
"Ranking" => 1
]
"Specialisation" => array:3 [▼
0 => array:3 [▼
"ID" => 1
"Name" => "Cardiology"
"SpecialistID" => 0
]
1 => array:3 [▼
"ID" => 15
"Name" => "General practice"
"SpecialistID" => 0
]
2 => array:3 [▼
"ID" => 19
"Name" => "Internal medicine"
"SpecialistID" => 0
]
]
]
1 => array:2 [▼
"Issue" => array:7 [▼
"ID" => 87
"Name" => "Heart attack"
"Accuracy" => 67.49999
"Icd" => "I21;I22"
"IcdName" => "Acute myocardial infarction;Subsequent myocardial infarction"
"ProfName" => "Myocardial infarction"
"Ranking" => 2
]
"Specialisation" => array:3 [▼
0 => array:3 [▼
"ID" => 1
"Name" => "Cardiology"
"SpecialistID" => 0
]
1 => array:3 [▼
"ID" => 15
"Name" => "General practice"
"SpecialistID" => 0
]
2 => array:3 [▼
"ID" => 19
"Name" => "Internal medicine"
"SpecialistID" => 0
]
]
]
2 => array:2 [▼
"Issue" => array:7 [▼
"ID" => 167
"Name" => "Obstruction of a pulmonary artery"
"Accuracy" => 28.125
"Icd" => "I26"
"IcdName" => "Pulmonary embolism"
"ProfName" => "Pulmonary embolism"
"Ranking" => 3
]
"Specialisation" => array:3 [▼
0 => array:3 [▼
"ID" => 15
"Name" => "General practice"
"SpecialistID" => 0
]
1 => array:3 [▼
"ID" => 19
"Name" => "Internal medicine"
"SpecialistID" => 0
]
2 => array:3 [▼
"ID" => 35
"Name" => "Pulmonology"
"SpecialistID" => 0
]
]
]
]