all(), [ 'name' => 'required', //'mobile_number' => 'regex:/07\d{2} \d{3} \d{3}/' //'mobile_number' => 'regex:/(07)[0-9]{8}/' ]); if ($validator->fails()) { $string = ""; foreach ($validator->errors()->getMessages() as $item) { $string .= "{$item[0]}
"; } return back()->withErrors($validator)->withInput(); } else { $logged_in_user_id = Auth::user()->id; $lab_form = new LabForm; $lab_form->name = $request->name; $lab_form->created_by = $logged_in_user_id; $lab_form->updated_by = $logged_in_user_id; try { $lab_form->save(); flash($request->name . " LabForm has been saved")->success(); return redirect("/lab_forms/"); } catch (QueryException $e) { flash("An error occurred")->error(); return back()->withInput(); } } } /** * Display the specified resource. * * @param \Streamline\Models\LabForm $labForm * @return \Illuminate\Http\Response */ public function show(LabForm $labForm) { // } /** * Show the form for editing the specified resource. * * @param \Streamline\Models\LabForm $labForm * @return \Illuminate\Http\Response */ public function edit($id) { $lab_form = LabForm::where(['id' => $id])->first(); return view('investigations::lab_forms.edit', compact('lab_form')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \Streamline\Models\LabForm $labForm * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $validator = Validator::make($request->all(), [ 'name' => 'required', ]); if ($validator->fails()) { $string = ""; foreach ($validator->errors()->getMessages() as $item) { $string .= "{$item[0]}
"; } return back()->withErrors($validator)->withInput(); } else { $logged_in_user_id = Auth::user()->id; $lab_form = LabForm::find($id); $lab_form->name = $request->name; $lab_form->updated_by = $logged_in_user_id; try { $lab_form->save(); flash($request->name . " LabForm has been updated")->success(); return redirect("/lab_forms/"); } catch (QueryException $e) { flash("An error occurred")->error(); return back()->withInput(); } } } /** * Remove the specified resource from storage. * * @param \Streamline\Models\LabForm $labForm * @return \Illuminate\Http\Response */ public function destroy($id) { $lab = LabForm::find($id); if ($lab->delete()) { flash("Lab has been deleted.")->success(); return redirect('labs'); } } public function inactive() { $lab_forms = LabForm::onlyTrashed() ->orderBy('name', 'asc') ->get(); if (count($lab_forms) < 1) { flash()->error("There is no inactive lab forms"); return redirect('lab_forms'); } return view('investigations::lab_forms.inactive', compact('lab_forms')); } /** * Activate the specified resource in storage. * * @param int $id * @return \Illuminate\Http\Response */ public function activate($id) { $lab_form = LabForm::withTrashed()->find($id); if($lab_form->restore()){ flash("Lab Form has been activated.")->success(); return redirect('/lab_forms/inactive'); } } }