public function tag($tag_str) { // Check tag $tag = Cache::remember('tag_str_' . $tag_str, 30, function () use($tag_str) { return \App\Tag::where('tag', $tag_str)->first(); }); if (!$tag) { App::abort(404); } // ------------------------------------------------------------------------ // QUERY // ------------------------------------------------------------------------ $max_data = 50; $tour_schedules_count = Cache::remember('tours_tag_count_' . $tag_str, 30, function () use($tag) { return \App\TourSchedule::published()->scheduledBetween(\Carbon\Carbon::now(), \Carbon\Carbon::now()->addYear(1))->InTagByIds($tag->id)->count(); }); $tour_schedules = Cache::remember('tours_tag_' . $tag_str, 30, function () use($tag, $max_data) { $tour_schedules = \App\TourSchedule::published()->scheduledBetween(\Carbon\Carbon::now(), \Carbon\Carbon::now()->addYear(1))->InTagByIds($tag->id)->orderBy('departure')->limit($max_data)->select(DB::raw(with(new \App\TourSchedule())->getTable() . '.*'))->get(); $tour_schedules->load('tour', 'tour.places', 'tour.options', 'tour.destinations', 'tour.destinations.images', 'tour.travel_agent', 'tour.travel_agent.images', 'tour.travel_agent.active_packages'); return $tour_schedules; }); $tour_schedules = $tour_schedules->sortBy(function ($data, $key) { return str_pad($data->tour->travel_agent->active_packages[0]->priority ? $data->tour->travel_agent->active_packages[0]->priority * -1 : 0, 2, 0, STR_PAD_LEFT) . $data->departure; }); // ------------------------------------------------------------------------ // PREPARE FILTERS FOR RESULTS // ------------------------------------------------------------------------ $filter_schedules = []; // durations foreach ($tour_schedules as $schedule) { $filter_schedules['durations'][$schedule->tour->duration_day * 1] = $schedule->tour->duration_day . 'D/' . $schedule->tour->duration_night . 'N'; $filter_schedules['travel_agents'][$schedule->tour->travel_agent->id] = $schedule->tour->travel_agent->name; if (!$filter_schedules['price']['min'] || $filter_schedules['price']['min'] > $schedule->discounted_price) { $filter_schedules['price']['min'] = $schedule->discounted_price; } if ($filter_schedules['price']['max'] < $schedule->discounted_price) { $filter_schedules['price']['max'] = $schedule->discounted_price; } } ksort($filter_schedules['durations']); asort($filter_schedules['travel_agents']); // ------------------------------------------------------------------------------------------------------------ // SHOW DISPLAY // ------------------------------------------------------------------------------------------------------------ $this->layout->page = view($this->page_base_dir . 'tours'); $this->layout->page->tour_schedules = $tour_schedules; $this->layout->page->tour_schedules_count = $tour_schedules_count; $this->layout->page->max_data = $max_data; $this->layout->page->tag = $tag; $this->layout->page->option_list = $this->option_list; $this->layout->page->filter_schedules = $filter_schedules; // search tour $this->layout->page->all_travel_agents = $this->all_travel_agents; $this->layout->page->all_destinations = $this->all_destinations; $this->layout->page->departure_list = $this->departure_list; $this->layout->page->budget_list = $this->budget_list; $this->layout->page->tour_shortcut = $this->tour_shortcut; $this->layout->title = "Paket Tour " . $tag->tag . ' - Capcus.id'; $this->layout->og['title'] = $this->layout->title; $this->layout->og['type'] = 'website'; $this->layout->og['image'] = $tour_schedules->count() ? $tour_schedules->first()->tour->places->first()->images->where('name', 'LargeImage')->first()->path : ''; $this->layout->og['image:type'] = 'jpg'; $this->layout->og['image:width'] = 800; $this->layout->og['image:height'] = 600; return $this->layout; }
public function show($destination_slug, $place_slug) { // ------------------------------------------------------------------------------------------------------------ // DETAIL PLACE // ------------------------------------------------------------------------------------------------------------ $place = Place::inDestinationByPath(str_replace(',', \App\Destination::getDelimiter(), $destination_slug))->slugIs($place_slug)->published()->first(); $place->load('images', 'destination'); if (!$place) { \App::abort(404); } // ------------------------------------------------------------------------------------------------------------ // OTHER PLACE FROM THE SAME DESTINATION // ------------------------------------------------------------------------------------------------------------ $other_places = Cache::remember('other_place_in_' . $place->destination->id, 60, function () use($destination_slug, $place) { $other_places = Place::inDestinationByPath(str_replace(',', \App\Destination::getDelimiter(), $destination_slug))->where('id', '!=', $place->id)->published()->limit(8)->get(); $other_places->load('images', 'destination'); return $other_places; }); // ------------------------------------------------------------------------------------------------------------ // PAKET TOUR KE TEMPAT INI // ------------------------------------------------------------------------------------------------------------ $tour_schedules = Cache::remember('upcoming_tour_to_place_' . $place->id, 60, function () use($place) { $tour_schedules = \App\TourSchedule::published()->whereHas('tour', function ($q) use($place) { $q->inPlaceByIds($place->id); })->scheduledBetween(\Carbon\Carbon::now(), \Carbon\Carbon::now()->addYear(1))->limit(5)->oldest('departure')->get(); $tour_schedules->load('tour', 'tour.travel_agent', 'tour.travel_agent.images', 'tour.travel_agent.active_packages', 'tour.places', 'tour.options', 'tour.destinations'); return $tour_schedules; }); // ------------------------------------------------------------------------------------------------------------ // SHOW DISPLAY // ------------------------------------------------------------------------------------------------------------ $this->layout->page = view($this->page_base_dir . 'place_detail'); $this->layout->page->place = $place; $this->layout->page->other_places = $other_places; $this->layout->page->tour_schedules = $tour_schedules; $this->layout->page->option_list = $this->option_list; $this->layout->title = $place->name . ' - Capcus.id'; $this->layout->og['title'] = $this->layout->title; $this->layout->og['type'] = 'article'; $this->layout->og['image'] = $place->images->where('name', 'Gallery1')->path; $this->layout->og['image:type'] = pathinfo('images/' . $this->layout->og['image'], PATHINFO_EXTENSION); $this->layout->og['image:width'] = 600; $this->layout->og['image:height'] = 400; return $this->layout; }