/** * Updates an advert with a new background selected via the user * @param \Illuminate\Http\Request $request * @param int $advertID ID of the advert to update its index * @return \Illuminate\Http\Response */ public function updateBackground(Request $request, $advertID) { $backgroundID = $request->input('background_id'); $advert = Advert::find($advertID); if ($advert == null) { abort(404); } $advert->background_id = $backgroundID; $advert->save(); return response('Success', 200); }
/** * Display the specified resource. * * @param int $id ID of the page to show * @return \Illuminate\Http\Response */ public function show($adID, $id) { $match = ['id' => $id, 'deleted' => 0]; $page = Page::where($match)->first(); // one to one only return 1 if ($page == null) { return redirect()->route('dashboard.advert.edit', [$adID])->with('message', 'Error: Could not find page'); } $pageData = $page->PageData->where('id', $page->page_data_id)->orderBy('heading', 'ASC')->first(); $advert = Advert::find($adID); if ($advert == null) { return redirect()->route('dashboard.advert.edit', [$adID])->with('message', 'Error: Advert removed before update'); } $background = Background::find($advert->background_id); if ($background == null) { return redirect()->route('dashboard.advert.edit', [$adID])->with('message', 'Error: Background removed before update'); } $data = array('page' => $page, 'pageData' => $pageData, 'activeTemplate' => $page->Template, 'templates' => Template::all(), 'advertBackground' => $background); return view('pages/pageeditor', $data); }