$status]); } /** * Show the form for creating a new resource. * * @param Request $request * @return Application|Factory|View|RedirectResponse */ public function create(Request $request) { return \view("state.create"); } /** * Store a newly created resource in storage. * * @param Request $request * @return RedirectResponse */ public function store(Request $request) : RedirectResponse { $rawstatus = $request->validate([ 'name' => 'required|string' ]); $status = new Status($rawstatus); if($status->save()) { return redirect()->route("index"); } return redirect()->route("error"); } /** * Display the specified resource. * * @param Status $status * @return View */ public function show(Status $status) : View { return view("state.show-status")->with([ "state" => $status ]); } /** * Show the form for editing the specified resource. * * @param Status $status * @return Response */ public function edit(Status $status): Response { // } /** * Update the specified resource in storage. * * @param Request $request * @param Status $status * @return View */ public function update(Request $request, Status $status): View { $data = $request->validate([ 'name' => 'required|string' ]); $status->update($data); if(!$status->save()){ return view("state.show-status", [ "states" => $status ]); }else{ $states = Status::all(); return view("state.index", ['states' => $states, "success" => "Opdaterede state"]); } } /** * Remove the specified resource from storage. * * @param Status $status * @return RedirectResponse */ public function destroy(Status $status): RedirectResponse { $status->posts()->delete(); $status->delete(); return redirect()->route("index"); } }