Created
November 6, 2020 11:35
-
-
Save prodhan/f64cb71caf456c936e08bad66d6d6670 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use App\Patient; | |
| use App\Prescription; | |
| use Carbon\Carbon; | |
| use Illuminate\Http\Request; | |
| class PatientController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index() | |
| { | |
| $date = Carbon::now()->subDays(30); | |
| $patients = Patient::where('created_at', '>=', $date)->orderBy('id', 'DESC')->get(); | |
| return view('patients.index', compact('patients')); | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function create() | |
| { | |
| return view('patients.create'); | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function store(Request $request) | |
| { | |
| $input = $request->all(); | |
| try { | |
| $data = Patient::create($input); | |
| $bug = 0; | |
| } catch (\Exception $e) { | |
| $bug = 1; | |
| return $e; | |
| } | |
| if ($bug == 0) { | |
| return redirect('/patients')->with('success', 'New Patient has been added'); | |
| } else { | |
| return redirect()->back()->with('error', 'Something went wrong!')->withInput(); | |
| } | |
| } | |
| /** | |
| * Display the specified resource. | |
| * | |
| * @param \App\Patient $patient | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function show(Patient $patient) | |
| { | |
| $prescriptions = Prescription::where('patient_id', $patient->id)->get(); | |
| return view('patients.show', compact('patient', 'prescriptions')); | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param \App\Patient $patient | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function edit($id) | |
| { | |
| $data = Patient::findOrFail($id); | |
| return view('patients.edit', compact('data')); | |
| } | |
| /** | |
| * Update the specified resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param \App\Patient $patient | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function update(Request $request, $id) | |
| { | |
| $data = Patient::findOrFail($id); | |
| $input = $request->all(); | |
| try { | |
| $data->update($input); | |
| $bug = 0; | |
| } catch (\Exception $e) { | |
| $bug = $e->errorInfo[1]; | |
| } | |
| if ($bug == 0) { | |
| return redirect('/patients')->with('success', 'Information has been updated!'); | |
| } else { | |
| return redirect()->back()->with('error', 'Something went wrong!')->withInput(); | |
| } | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param \App\Patient $patient | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function destroy($id) | |
| { | |
| $data = Patient::findOrFail($id); | |
| $data->delete(); | |
| return redirect()->back()->with('info', 'Info has been Deleted!'); | |
| } | |
| public function search(Request $request) | |
| { | |
| $mobile = $request->mobile; | |
| $patients = Patient::where('phone', $mobile)->get(); | |
| return view('patients.index', compact('patients')); | |
| } | |
| public function get_patient($mobile){ | |
| $data = Patient::where('phone', '=', $mobile)->first(); | |
| return json_encode($data); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment