middleware([ "auth" ]); $this->middleware([ "lang" ]); $this->middleware([ "check.auth:menuplan.list" ])->only("index"); $this->middleware([ "check.auth:menuplan.show" ])->only("show"); $this->middleware([ "check.auth:menuplan.create" ])->only("create", "store"); $this->middleware([ "check.auth:menuplan.edit" ])->only("edit", "update"); $this->middleware([ "check.auth:menuplan.delete" ])->only("delete"); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $menuPlans = MenuPlan::query()->paginate($request->input("limit", 20)); return Response::detect("menuplans.index", [ "menuPlans" => $menuPlans]); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return Response::detect("menuplans.create"); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $requestMenuPlanCreate = $request->validate([ "week" => "required|max:2", "menu" => "required", ]); $menuPlan = new MenuPlan($requestMenuPlanCreate); $allMenuPlans = MenuPlan::query()->where('week', '=', $request->week)->get(); if(count($allMenuPlans) > 0) return redirect()->route("menu-plans.index")->with('WeekExists', '
Der findes allerede en menuplan for den uge!
'); else { $menuPlan->save(); $menuPlans = MenuPlan::query()->paginate($request->input("limit", 20)); if($request->newsoption == true){ $news = new News(); $news->name = "Ny menuplan"; $news->subname = "Uge " . $menuPlan->week; $news->content = $menuPlan->menu; if($request->file("resource")) { $news->resource_id = ResourceController::store($request)->id; } $news->save(); } return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]); } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(MenuPlan $id) { return Response::detect("menuplans.show", [ "menuplan" => $id]); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $menuplan = MenuPlan::find($id); return Response::detect("menuplans.edit", ["menuplan" => $menuplan]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $data = $request->all(); //FORCED UPDATE $menuplan = MenuPlan::find($id); $allMenuPlans = MenuPlan::query()->where('week', '=', $request->week)->where('id', '!=', $id)->get(); if(count($allMenuPlans) > 0){ return redirect()->route("menu-plans.index")->with('WeekExists', 'Der findes allerede en menuplan for den uge!
'); }else{ $menuplan->update($data); $menuplan->save(); $menuPlans = MenuPlan::query()->paginate($request->input("limit", 20)); if($request->newsoption == true){ $news = [ "name" => "Opdateret menuplan", "subname" => "Uge " . $menuplan->week, "content" => $menuplan->menu ]; NewsController::storeAndGet($news); } return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]); } } /** * Remove the specified resource from storage. * Test delete return index function. * @param int $id * @return \Illuminate\Http\RedirectResponse */ public function destroy($id) { $menuplan = MenuPlan::find($id); $menuplan->delete(); return redirect()->route("menu-plans.index"); } }