public static function storeHighRiskMeds($request, $record_id) { $high_risk_meds = HighRiskMeds::whereRecordId($record_id)->first(); if (count($high_risk_meds) == 0) { $high_risk_meds = new HighRiskMeds(); $high_risk_meds->record_id = $record_id; $high_risk_meds->user_id = Auth::user()->id; $high_risk_meds->q1 = $request->get('q1'); $high_risk_meds->q1_a = $request->get('q1_a'); $high_risk_meds->q2 = $request->get('q2'); $high_risk_meds->q3 = $request->get('q3'); $high_risk_meds->q4 = $request->get('q4'); $high_risk_meds->q4_a = $request->get('q4_a'); $high_risk_meds->q5 = $request->get('q5'); if ($high_risk_meds->save()) { // Touch parent model $record = Record::find($record_id); $record->touch(); return redirect()->back()->with('message', 'Answer sheet was successfully saved.')->with('msg_type', 'positive'); } else { return redirect()->back()->with('message', 'Answer sheet was not saved. Please review the answers')->with('msg_type', 'negative'); } } else { $high_risk_meds->update(['q1' => $request->get('q1'), 'q1_a' => $request->get('q1_a'), 'q2' => $request->get('q2'), 'q3' => $request->get('q3'), 'q4' => $request->get('q4'), 'q4_a' => $request->get('q4_a'), 'q5' => $request->get('q5')]); // Touch parent model $record = Record::find($record_id); $record->touch(); return redirect()->back()->with('message', 'Answer sheet was successfully updated.')->with('msg_type', 'positive'); } }
public function store(Request $request, $record_id) { HighRiskMeds::unguard(); $store_high_risk_meds = HighRiskMeds::storeHighRiskMeds($request, $record_id); return $store_high_risk_meds; }