public function patient_aprrovedischarge(Request $request, $id)
{
//get patient details
$patientDischarge = DischargedPatients::where('id', '=', $id)->first();
//find patient update to DISCHARGE pending
$updatepatient = Patients::find($patientDischarge->patient_id);
$updatepatient->user_currently_at = 'DISCHARGED';
// //update discharge details
$dischargepatient = DischargedPatients::find($id);
$dischargepatient->status = 'approved';
$dischargepatient->discharged_by = auth()->user()->id;
$dischargepatient->discharged_date = date('Y-m-d H:i:s');
// //save remarks
$dischargeRemarks = new Remarks();
$dischargeRemarks->remarks_detail = 'Discharged Aprroved';
$dischargeRemarks->remarks_from = auth()->user()->id;
$dischargeRemarks->user_from_type = 'MO';
$dischargeRemarks->patient_id = $patientDischarge->patient_id;
$updatepatient->save();
$dischargepatient->save();
$dischargeRemarks->save();
return redirect('/medical/discharged')->with('success', 'Patient is now discharged!');
}
sorry , im not good with stack overflow, my problem is that not all of these 3 saves are on the database. its already uploaded on the hosting, maybe anyone can explain why, i think it has problem with the internet since sometimes it disconnects
CodePudding user response:
You are trying to save same record twice, basically $patientDischarge
and $dischargepatient
are same records.
public function patient_aprrovedischarge(Request $request, $id)
{
//get patient details
$patientDischarge = DischargedPatients::findOrFail($id);
$patientDischarge->status = 'approved';
$patientDischarge->discharged_by = auth()->id();
$patientDischarge->discharged_date = date('Y-m-d H:i:s');
$patientDischarge->save();
//find patient update to DISCHARGE pending
$updatepatient = Patients::findOrFail($patientDischarge->patient_id);
$updatepatient->update([
'user_currently_at' => 'DISCHARGED',
]);
Remarks::create([
'remarks_detail' => 'Discharged Aprroved',
'remarks_from' => auth()->id(),
'user_from_type' => 'MO',
'patient_id' => $patientDischarge->patient_id,
])
return redirect('/medical/discharged')->with('success', 'Patient is now discharged!');
}