middleware('auth'); $this->middleware('permission:drug-form-list', ['only' => ['index']]); $this->middleware('permission:drug-form-create', ['only' => ['create', 'store']]); $this->middleware('permission:drug-form-edit', ['only' => ['edit', 'update']]); $this->middleware('permission:drug-form-delete', ['only' => ['destroy', 'inactive', 'activate']]); } /**create * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $drug_forms = DrugForm::orderBy('name', 'asc') ->paginate(50); return view('clinical_data::drug_forms.index', compact('drug_forms')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return view('clinical_data::drug_forms.create'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { request()->validate([ 'name' => 'required' ]); $logged_in_user_id = Auth::user()->id; $drug_form = new DrugForm; $drug_form->name = $request->name; $drug_form->created_by = $logged_in_user_id; $drug_form->updated_by = $logged_in_user_id; try { $drug_form->save(); flash($request->name . " drug form has been saved")->success(); return redirect("/drug_forms/"); } catch (QueryException $e) { flash("An error occurred")->error(); return back()->withInput(); } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $drug_form = DrugForm::where(['id' => $id])->first(); if (!$drug_form) { flash()->error("Drug Form not found"); return redirect('/drug_forms/'); } else { return view('clinical_data::drug_forms.edit', compact('drug_form')); } } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { request()->validate([ 'name' => 'required' ]); $logged_in_user_id = Auth::user()->id; $drug_form = DrugForm::find($id); $drug_form->name = $request->name; $drug_form->updated_by = $logged_in_user_id; try { $drug_form->save(); flash($request->name . " Drug Form has been updated")->success(); return redirect("/drug_forms/"); } catch (QueryException $e) { flash("An error occurred")->error(); return back()->withInput(); } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $drug_form = DrugForm::find($id); if ($drug_form->delete()){ flash("Form has been deleted.")->success(); return redirect('/drug_forms/'); } } /** * Display a listing of the inactive resource(s). * * @return \Illuminate\Http\Response */ public function inactive() { $drug_forms = DrugForm::onlyTrashed() ->orderBy('name', 'asc') ->paginate(50); if (count($drug_forms) < 1) { flash()->error("There is no inactive Forms"); return redirect('/drug_forms/'); } else { return view('clinical_data::drug_forms.inactive', compact('drug_forms')); } } /** * Activate the specified resource in storage. * * @param int $id * @return \Illuminate\Http\Response */ public function activate($id) { $drug_form = DrugForm::withTrashed()->find($id); if ($drug_form->restore()){ flash("Form has been activated.")->success(); return redirect('/drug_forms/'); } } }