$occupations]); } /** * Show the form for creating a new resource. * * @return View */ public function create(): View { return view("occupation.create"); } /** * Store a newly created resource in storage. * * @param Request $request * @return RedirectResponse */ public function store(Request $request) : RedirectResponse { $rawOccupation = $request->validate([ 'name' => 'required|string' ]); $Occupation = new Occupation($rawOccupation); if($Occupation->save()) { return redirect()->route("index"); } return redirect()->route("error"); } /** * Show the form for editing the specified resource. * * @param Occupation $occupation * @return Response */ public function edit(Occupation $occupation) { return \view("occupation.show-occupation")->with([ "occupation" => $occupation ]); } /** * Update the specified resource in storage. * * @param Request $request * @param Occupation $occupation * @return View */ public function update(Request $request, Occupation $occupation): View { $data = $request->validate([ 'name' => 'required|string' ]); $occupation->update($data); if(!$occupation->save()){ return view("occupation.show-occupation", [ "occupation" => $occupation, "error" => "occupation was not updated" ]); }else{ return view("occupation.show-occupation", [ "occupation" => $occupation, "success" => "updated occupation" ]); } } /** * Remove the specified resource from storage. * * @param Occupation $occupation * @return RedirectResponse */ public function destroy(Occupation $occupation): RedirectResponse { $occupation->post()->delete(); if($occupation->delete()){ return redirect()->route("index"); } return redirect()->route("error"); } }