/** * Display the specified resource. * * @param int $id * @return Response */ public function show($slug) { $media = $this->media->where('slug', '=', $slug)->first(); if (isset($media)) { $view_increment = $this->handleViewCount($media->id); $next = Media::where('active', '=', 1)->where('created_at', '>', date("Y-m-d H:i:s", strtotime($media->created_at)))->first(); $previous = Media::where('active', '=', 1)->where('created_at', '<', date("Y-m-d H:i:s", strtotime($media->created_at)))->orderBy('created_at', 'desc')->first(); $media_next = Media::where('active', '=', 1)->where('created_at', '>=', date("Y-m-d H:i:s", strtotime($media->created_at)))->take(6)->get(); $next_media_count = $media_next->count(); if ($next_media_count < 6) { $get_prev_results = 6 - $next_media_count; $media_prev = Media::where('active', '=', 1)->where('created_at', '<', date("Y-m-d H:i:s", strtotime($media->created_at)))->orderBy('created_at', 'DESC')->take($get_prev_results)->get(); } else { $media_prev = array(); } $data = array('media' => $media, 'media_next' => $media_next, 'next' => $next, 'previous' => $previous, 'media_prev' => $media_prev, 'view' => 'single', 'view_increment' => $view_increment); return View::make('media.show', $data); } else { return Redirect::to('/'); } }