Beispiel #1
0
 public function show($travel_agent_slug, $tour_slug, $schedule)
 {
     // ------------------------------------------------------------------------------------------------------------
     // DETAIL TOUR
     // ------------------------------------------------------------------------------------------------------------
     $tour = Cache::remember('tour_by_slug_' . $travel_agent_slug . $tour_slug . $schedule, 30, function () use($tour_slug) {
         $tour = Tour::slugIs($tour_slug)->first();
         if ($tour) {
             $tour->load('schedules', 'travel_agent', 'travel_agent.images', 'places', 'places.images', 'places.destination', 'destinations');
         }
         return $tour;
     });
     if (!$tour) {
         \App::abort(404);
     }
     // check travel agent
     if (!str_is(strtolower($travel_agent_slug), $tour->travel_agent->slug)) {
         \App::abort(404);
     }
     // get schedule
     foreach ($tour->schedules as $x) {
         if ($x->departure->format('Ymd') == \Carbon\Carbon::parse(substr($schedule, 0, 4) . '-' . substr($schedule, 4, 2) . '-' . substr($schedule, 6, 2))->format('Ymd')) {
             $tour_schedule = $x;
             break;
         }
     }
     $tour_schedule->views++;
     $tour_schedule->save();
     // ------------------------------------------------------------------------------------------------------------
     // OTHER TOUR WITH SIMILAR DESTINATION
     // ------------------------------------------------------------------------------------------------------------
     $other_tours['by_destination'] = Cache::remember('related_tour_schedules_by_destination_of_' . $tour_schedule->id, 30, function () use($tour, $tour_schedule) {
         $data = $this->dispatch(new FindPublishedTourSchedules(\Carbon\Carbon::parse($tour_schedule->departure)->SubDay(30)->gt(\Carbon\Carbon::now()) ? \Carbon\Carbon::parse($tour_schedule->departure)->SubDay(30) : \Carbon\Carbon::now(), \Carbon\Carbon::parse($tour_schedule->departure)->SubDay(30)->gt(\Carbon\Carbon::now()) ? \Carbon\Carbon::parse($tour_schedule->departure)->addDay(30) : \Carbon\Carbon::now()->addDay(30), $tour->destinations->lists('id')->toArray(), 0, 999999999, null, null, 0, 15));
         $data->load('tour', 'tour.travel_agent', 'tour.travel_agent.images', 'tour.travel_agent.active_packages', 'tour.places', 'tour.places.images', 'tour.destinations', 'tour.options');
         return $data;
     });
     // ------------------------------------------------------------------------------------------------------------
     // OTHER TOUR BY DEPARTURE
     // ------------------------------------------------------------------------------------------------------------
     $other_tour_options['by_departure_start_date'] = \Carbon\Carbon::parse($tour_schedule->departure)->SubDay(3);
     $other_tour_options['by_departure_end_date'] = \Carbon\Carbon::parse($tour_schedule->departure)->AddDay(3);
     $other_tours['by_departure'] = Cache::remember('related_tour_schedules_by_departure_of_' . $tour_schedule->id, 30, function () use($tour, $tour_schedule) {
         $data = $this->dispatch(new FindPublishedTourSchedules($other_tour_options['by_departure_start_date'], $other_tour_options['by_departure_end_date'], null, 0, 999999999, null, null, 0, 15));
         $data->load('tour', 'tour.travel_agent', 'tour.travel_agent.active_packages', 'tour.places', 'tour.destinations', 'tour.travel_agent.images', 'tour.options');
         return $data;
     });
     // ------------------------------------------------------------------------------------------------------------
     // OTHER TOUR BY BUDGET
     // ------------------------------------------------------------------------------------------------------------
     $other_tour_options['by_budget_start_date'] = \Carbon\Carbon::parse($tour_schedule->departure)->SubDay(30)->gt(\Carbon\Carbon::now()) ? \Carbon\Carbon::parse($tour_schedule->departure)->SubDay(30) : \Carbon\Carbon::now();
     $other_tour_options['by_budget_end_date'] = \Carbon\Carbon::parse($tour_schedule->departure)->SubDay(30)->gt(\Carbon\Carbon::now()) ? \Carbon\Carbon::parse($tour_schedule->departure)->addDay(30) : \Carbon\Carbon::now()->addDay(30);
     $other_tour_options['by_budget_start'] = $tour_schedule->discounted_price * 80 / 100;
     $other_tour_options['by_budget_end'] = $tour_schedule->discounted_price * 120 / 100;
     $other_tours['by_budget'] = Cache::remember('related_tour_schedules_by_budget_of_' . $tour_schedule->id, 30, function () use($tour, $tour_schedule) {
         $data = $this->dispatch(new FindPublishedTourSchedules($other_tour_options['by_budget_start_date'], $other_tour_options['by_budget_end_date'], null, $other_tour_options['by_budget_start'], $other_tour_options['by_budget_end'], null, null, 0, 15));
         $data->load('tour', 'tour.travel_agent', 'tour.travel_agent.active_packages', 'tour.places', 'tour.places.destination', 'tour.places.images', 'tour.destinations', 'tour.travel_agent.images', 'tour.options');
         return $data;
     });
     // ------------------------------------------------------------------------------------------------------------
     // REMOVE CURRENT TOUR SCHEDULE IN OTHER TOUR
     // ------------------------------------------------------------------------------------------------------------
     $current_schedule_id = $tour_schedule->id;
     foreach ($other_tours as $k => $v) {
         if ($v) {
             $other_tours[$k] = $v->reject(function ($item) use($k, $current_schedule_id) {
                 return $item->id == $current_schedule_id;
             });
         }
     }
     // ------------------------------------------------------------------------------------------------------------
     // SHOW DISPLAY
     // ------------------------------------------------------------------------------------------------------------
     $this->layout->page = view($this->page_base_dir . 'tour_detail');
     $this->layout->page->tour = $tour;
     $this->layout->page->tour_schedule = $tour_schedule;
     $this->layout->page->other_tours = $other_tours;
     $this->layout->page->other_tour_options = $other_tour_options;
     $this->layout->page->option_list = $this->option_list;
     $this->layout->page->tour_shortcut = $this->tour_shortcut;
     $this->layout->title = "Paket Tour " . $tour->name . ' oleh ' . $tour->travel_agent->name . ' tgl ' . (is_null($tour_schedule->departure_until) ? $tour_schedule->departure->format('d-m-Y') : ' keberangkatan kapanpun antara ' . $tour_schedule->departure->format('d-m-Y') . ' s/d ' . $tour_schedule->departure_until->format('d-m-Y')) . ' - Capcus.id';
     //
     $this->layout->og['title'] = $this->layout->title;
     $this->layout->og['type'] = 'article';
     $this->layout->og['image'] = $tour->places->first() ? $tour->places->first()->images->where('name', 'LargeImage')->first()->path : asset('images/logo/logo-new.png');
     $this->layout->og['image:type'] = 'jpg';
     $this->layout->og['image:width'] = 800;
     $this->layout->og['image:height'] = 600;
     $this->layout->og['article:published_time'] = $tour->published_at->format('Y-m-d H:i:s');
     $this->layout->og['article:section'] = 'paket tour';
     $this->layout->og['article:tag'] = implode(', ', $tour->destinations->lists('name')->toArray());
     return $this->layout;
 }