paginate(50); return view('clinical_data::test_areas.index', compact('test_areas')); } /** * Show the form for creating a new resource. * */ public function create() { return view('clinical_data::test_areas.create'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), [ 'name' => 'required' ]); if ($validator->fails()) { //validation failed $string = ""; foreach ($validator->errors()->getMessages() as $item) { $string .= "{$item[0]}
"; } return back()->withErrors($validator)->withInput(); } else { //validation passed $test_area = new SlitLampTestArea; $logged_in_user_id = Auth::user()->id; $test_area->name = $request->name; $test_area->slug = "slit_".substr($request->name, 0, 2); $test_area->created_by = $logged_in_user_id; $test_area->updated_by = $logged_in_user_id; try { $test_area->save(); flash($request->name . " Staff Position has been saved")->success(); return redirect("/test_areas/"); } 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) { $test_area = SlitLampTestArea::where(['id' => $id])->first(); if (!$test_area) { flash()->error("There is no such staff position"); return redirect('/test_areas/'); } else { return view('clinical_data::test_areas.edit', compact('test_area')); } } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $validator = Validator::make($request->all(), [ 'name' => 'required' ]); if ($validator->fails()) { //validation failed $string = ""; foreach ($validator->errors()->getMessages() as $item) { $string .= "{$item[0]}
"; } // flash($string)->error(); return back()->withErrors($validator)->withInput(); } else { //validation passed $test_area = SlitLampTestArea::find($id); $test_area->name = $request->name; try { $test_area->save(); flash($request->name . " Staff Position has been updated")->success(); return redirect("/test_areas/"); } 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) { $test_area = SlitLampTestArea::findOrFail($id); if ($test_area->delete()): flash("Staff Position has been deleted.")->success(); return redirect('/test_areas/'); endif; } /** * Display a listing of the inactive resource(s). * * @return \Illuminate\Http\Response */ public function inactive() { $test_areas = SlitLampTestArea::onlyTrashed() ->orderBy('name', 'asc') ->paginate(50); if (count($test_areas) < 1) { flash()->error("There is no inactive staff position"); return redirect('/test_areas/'); } else { return view('clinical_data::test_areas.inactive', compact('test_areas')); } } /** * Activate the specified resource in storage. * * @param int $id * @return \Illuminate\Http\Response */ public function activate($id) { $test_area = SlitLampTestArea::withTrashed()->findOrFail($id); if ($test_area->restore()): flash("Staff Position has been activated.")->success(); return redirect('/test_areas/inactive'); endif; } }