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; $news->type_id = '2'; $news->arrangement_id = $menuPlan->id; if($request->file("resource")) { $news->resource_id = ResourceController::store($request)->id; } NewsController::storeAndGet($news); } 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 = new News(); $news->name = "Opdateret menuplan"; $news->subname = "Uge " . $menuplan->week; $news->arrangement_id = $menuplan->id; $news->type_id = '2'; $news->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 RedirectResponse */ public function destroy($id) { $menuplan = MenuPlan::find($id); $menuplan->delete(); return redirect()->route("menu-plans.index"); } /** * Remove the specified resource from storage. * Test delete return index function. * @param $Id * @return RedirectResponse */ public function genPDF($Id){ $menuPlan = MenuPlan::query()->where("id", "=", $Id)->first(); //$images = App\Resource::query()->where("id", '=', $menuPlan->resource_id)->first(); //$imagesSize = getimagesize($images->filename); $pdf = \Illuminate\Support\Facades\App::make('dompdf.wrapper'); $data = '