/**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     // Get selected Background
     $background = Background::find($id);
     if ($background == null) {
         return redirect()->route('dashboard.settings.backgrounds.index')->with('message', 'Error: Background not found');
     }
     // Ensure this background is not assigned to an advert
     $count = $background->Adverts()->count();
     if ($count != 0) {
         return redirect()->route('dashboard.settings.backgrounds.index')->with('message', 'Unable to delete ' . $background->name . ', as one or more adverts require it.');
     }
     $background->delete();
     // Delete
     return redirect()->route('dashboard.settings.backgrounds.index')->with('message', 'Background deleted successfully');
 }
 /**
  * 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);
 }