/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $input = $request->all();
     // Format phone number. Ex: (+84) 909787874
     $input['phone'] = '(' . $input['phoneCode'] . ')' . $input['phone'];
     // Format date for database insert
     $input['arrival_date'] = date('Y-m-d', strtotime($input['arrival_date']));
     $input['departure_date'] = date('Y-m-d', strtotime($input['departure_date']));
     // Format hotel room refernce for saving
     $single = $input['single'];
     $double = $input['double'];
     $twin = $input['twin'];
     $triple = $input['triple'];
     $input['hotel_room_reference'] = json_encode(compact('single', 'double', 'twin', 'triple'));
     $booking = TourBooking::create($input);
     // Send email to customer
     Mail::send('email.booking', $input, function ($message) use($input) {
         $message->from('*****@*****.**', 'Akjra Vu');
         $message->to($input['email'])->subject(Config::get('myconfig.SITE_NAME') . ' - Booking!');
     });
     Session::flash('request_message', 'Your request has been sent successfully. Thank you!');
     $booking = TourBooking::findOrFail($booking->id);
     // hard code alias for testing
     return view('booking.step3', ['booking' => $booking, 'tour' => Tour::find($input['tour_id'])]);
 }
예제 #2
0
 public function toggle_love()
 {
     $tour_slug = Input::get('tour_slug');
     // get user
     $user = Auth::user();
     if (!$user) {
         $jsend = new \ThunderID\jsend\jsend('fail', ['error' => 'Login Required']);
         return Response::json($jsend->toArray(), 400);
     }
     // get tour
     $tour = Tour::SlugIs($tour_slug)->first();
     if (!$tour) {
         $jsend = new \ThunderID\jsend\jsend('fail', ['error' => 'Tour not found']);
         return Response::json($jsend->toArray(), 400);
     }
     // add love
     $already_love = false;
     foreach ($user->love as $x) {
         if ($x->id == $tour->id) {
             $already_love = true;
         }
     }
     if ($already_love) {
         $user->love()->detach($tour->id);
     } else {
         $user->love()->attach($tour->id);
     }
     // return message
     $jsend = new \ThunderID\jsend\jsend('success', ['love' => $already_love ? 0 : 1]);
     return Response::json($jsend->toArray(), 200);
 }
예제 #3
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $model = Tour::findOrFail($id);
     $model->tourAuthor;
     $model->tourCategory;
     $model->tourComment;
     $model->tourComment->tourUser;
     return $model;
 }
예제 #4
0
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // We want to delete the comments table if it exists before running the seed
        DB::table('tours')->delete();
        $tours = array(['category_id' => 1, 'user_id' => 1, 'title' => 'Tallinn Free Walking Tour', 'image' => 'img22.jpg', 'description' => 'There is a fun and inexpensive, yet very informative way to get to know Tallinn- join the Free Walking Tour.
Great for people who dont mind sharing their tour experience with other fellow travelers.', 'likes' => 10], ['category_id' => 2, 'user_id' => 1, 'title' => 'Viru Bog and Kolga Manor Tour', 'image' => 'img22.jpg', 'description' => 'A visit to the Viru Bog has become a tradition, included in almost every tour operators excursion to Lahemaa. The Kolga Manor  is a "fair" and authentic place, quite different from the dressy manors of Palmse or Vihula.  Few dare to take their guests to the Kolga Manor.', 'likes' => 5], ['category_id' => 3, 'user_id' => 2, 'title' => 'A Day in Western Estonia', 'image' => 'img22.jpg', 'description' => 'Charming and historic Haapsalu with its Episcopal Castle, beach promenade, distinctive wooden houses and the White Lady. Meadows and beaches along with the refreshing sea to take a dip in. Castles with colourful histories and whatever is left of them.', 'likes' => 0], ['category_id' => 3, 'user_id' => 2, 'title' => 'A Day in Western Estonia', 'image' => 'img22.jpg', 'description' => 'Charming and historic Haapsalu with its Episcopal Castle, beach promenade, distinctive wooden houses and the White Lady. Meadows and beaches along with the refreshing sea to take a dip in. Castles with colourful histories and whatever is left of them.', 'likes' => 0], ['category_id' => 3, 'user_id' => 2, 'title' => 'A Day in Western Estonia', 'image' => 'img22.jpg', 'description' => 'Charming and historic Haapsalu with its Episcopal Castle, beach promenade, distinctive wooden houses and the White Lady. Meadows and beaches along with the refreshing sea to take a dip in. Castles with colourful histories and whatever is left of them.', 'likes' => 0], ['category_id' => 3, 'user_id' => 2, 'title' => 'A Day in Western Estonia', 'image' => 'img22.jpg', 'description' => 'Charming and historic Haapsalu with its Episcopal Castle, beach promenade, distinctive wooden houses and the White Lady. Meadows and beaches along with the refreshing sea to take a dip in. Castles with colourful histories and whatever is left of them.', 'likes' => 0], ['category_id' => 3, 'user_id' => 2, 'title' => 'A Day in Western Estonia', 'image' => 'img22.jpg', 'description' => 'Charming and historic Haapsalu with its Episcopal Castle, beach promenade, distinctive wooden houses and the White Lady. Meadows and beaches along with the refreshing sea to take a dip in. Castles with colourful histories and whatever is left of them.', 'likes' => 0]);
        foreach ($tours as $tour) {
            Tour::create($tour);
        }
    }
예제 #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // ------------------------------------------------------------------------------------------------------------
     // GET HEADLINE
     // ------------------------------------------------------------------------------------------------------------
     $headlines = \App\Headline::with('travel_agent')->activeOn(\Carbon\Carbon::now())->orderBy('priority')->get();
     $headlines = $headlines->sortByDesc(function ($data) {
         return $data->travel_agent->active_packages[0]->priority;
     });
     // ------------------------------------------------------------------------------------------------------------
     // GET HOMEGRID
     // ------------------------------------------------------------------------------------------------------------
     $homegrids = \App\HomegridSetting::orderby('name')->get();
     // get upcoming package schedules
     $homegrid_destination_ids = new Collection();
     foreach ($homegrids as $k => $v) {
         if (str_is('destination', $v->type)) {
             $homegrid_destination_ids->push($v->destination);
         }
     }
     if ($homegrid_destination_ids->count()) {
         $homegrid_destinations = \App\Destination::with('tours', 'tours.schedules')->whereIn('id', $homegrid_destination_ids)->get();
         foreach ($homegrids as $k => $v) {
             $homegrids[$k]->destination_detail = $homegrid_destinations->find($v->destination);
         }
     }
     // ------------------------------------------------------------------------------------------------------------
     // QUERY PAKET PROMO TERBARU
     // ------------------------------------------------------------------------------------------------------------
     $tours = \App\Tour::with('destinations', 'schedules', 'destinations.images', 'places', 'places.images', 'travel_agent', 'travel_agent.images', 'images')->has('schedules')->select('tours.*')->join('travel_agencies', 'travel_agencies.id', '=', 'travel_agent_id')->published()->latest('tours.created_at')->limit(8)->groupBy('travel_agent_id')->get();
     // ------------------------------------------------------------------------------------------------------------
     // GET BLOG TERBARU
     // ------------------------------------------------------------------------------------------------------------
     $articles = Article::with('images')->published()->latest('published_at')->take(6)->get();
     // ------------------------------------------------------------------------------------------------------------
     // GET USER
     // ------------------------------------------------------------------------------------------------------------
     $total_subscriber = \App\Subscriber::active()->count();
     $this->info(' ---------------------------------------------------------------------------------------------- ');
     $this->info(' BLAST NEWSLETTER ');
     $this->info(' ---------------------------------------------------------------------------------------------- ');
     $this->info(' * Sending Newsletter to ' . $total_subscriber . ' subscribers');
     \App\Subscriber::with('user')->active()->orderby('id')->chunk(100, function ($subscribers) {
         foreach ($subscribers as $subscriber) {
             Mail::queue('web.v4.emails.newsletters.weekly', ['headlines' => $headlines, 'homegrids' => $homegrids, 'tours' => $tours, 'articles' => $articles, 'subscriber' => $subscriber], function ($m) use($subscriber) {
                 $m->to($subscriber->email, $subscriber->user ? $subscriber->user->name : $subscriber->email)->subject('CAPCUS.id - Newsletter Edisi ' . \Carbon\Carbon::now()->year . '.' . \Carbon\Carbon::now()->format('W'));
             });
             $this->info(' * Newsletter sent to ' . $subscriber->email . ' *');
         }
     });
     $this->info(' ---------------------------------------------------------------------------------------------- ');
     $this->info(' BLAST NEWSLETTER COMPLETED');
     $this->info(' ---------------------------------------------------------------------------------------------- ');
 }
예제 #6
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $data = [];
     $data['tours'] = Tour::select('alias', 'name', 'duration')->latest('created_at')->where('day_tour', 0)->published()->take(6)->get();
     $data['day_tours'] = Tour::select('alias', 'name')->latest('created_at')->where('day_tour', 1)->published()->take(12)->get();
     $data['destinations'] = TourDestination::where('active', 1)->orderBy('name', 'ASC')->get();
     $data['reviews'] = TourReview::latest('created_at')->where('active', 1)->take(4)->get();
     $data['title'] = "Vietnam Tours - Planning tours to Vietnam with the best offers";
     $data['description'] = "Book travel for less with specials on cheap airline tickets, hotels, car rentals, and flights on TraveloVietnam.com, your one-stop resource for travel and vacation needs";
     $data['keywords'] = "vietnam travel, travel to vietnam, vietnam tours, tours in vietnam, vietnam hotels, hotels in vietnam, vietnam visa, visa to vietnam";
     return view('welcome', $data);
 }
예제 #7
0
 public function syncPhotos(Tour $tour, array $photoIds)
 {
     $tour_id = $tour->id;
     $tour->photos()->delete();
     foreach ($photoIds as $photo_id) {
         Photo::create(compact('tour_id', 'photo_id'));
     }
 }
예제 #8
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;
 }
예제 #9
0
 public function index()
 {
     // ------------------------------------------------------------------------------------------------------------
     // QUERY HEADLINE
     // ------------------------------------------------------------------------------------------------------------
     $headlines = Cache::remember('current_headline', 60, function () {
         return \App\Headline::activeOn(\Carbon\Carbon::now())->orderBy('priority')->get();
     });
     $headlines = $headlines->sortBy(function ($headline) {
         return rand(0, 1000);
     });
     // ------------------------------------------------------------------------------------------------------------
     // QUERY HOME GRID
     // ------------------------------------------------------------------------------------------------------------
     $homegrids = Cache::remember('current_homegrids', 60, function () {
         $homegrids = \App\HomegridSetting::orderBy('name')->get();
         // get upcoming package schedules
         $homegrid_destination_ids = new Collection();
         foreach ($homegrids as $k => $v) {
             if (str_is('destination', $v->type)) {
                 $homegrid_destination_ids->push($v->destination);
             }
         }
         //
         if ($homegrid_destination_ids->count()) {
             $homegrid_destinations = \App\Destination::with('tours', 'tours.schedules')->whereIn('id', $homegrid_destination_ids)->get();
             foreach ($homegrids as $k => $v) {
                 $homegrids[$k]->destination_detail = $homegrid_destinations->find($v->destination);
                 if (str_is('destination', $v->type)) {
                     $homegrids[$k]->destination_detail->total_upcoming_schedules;
                 }
             }
         }
         return $homegrids;
     });
     // ------------------------------------------------------------------------------------------------------------
     // QUERY PAKET PROMO
     // ------------------------------------------------------------------------------------------------------------
     // $promo_tours = Cache::remember('8_upcoming_promo_tours', 30, function(){
     // 	return \App\TourSchedule::with('tour', 'tour.places', 'tour.places.images' ,'tour.destinations', 'tour.destinations.images', 'tour.travel_agent', 'tour.travel_agent.images', 'tour.schedules', 'tour.images')
     // 								->published()
     // 								->promo()
     // 								->scheduledBetween(\Carbon\Carbon::now(), \Carbon\Carbon::now()->addYears(5))
     // 								->orderby('departure')
     // 								->limit(8)
     // 								->select('tour_schedules.*')
     // 								->join('tours', 'tours.id', '=', 'tour_schedules.tour_id')
     // 								->join('travel_agencies', 'travel_agencies.id', '=', 'tours.travel_agent_id')
     // 								->groupBy('tours.travel_agent_id')
     // 								->get();
     // });
     // ------------------------------------------------------------------------------------------------------------
     // QUERY PAKET TOUR TERBARU
     // ------------------------------------------------------------------------------------------------------------
     $latest_tours = Cache::remember('8_latest_tours_by_different_travel_agent', 30, function () {
         $all_latest_tours = \App\Tour::with('destinations', 'schedules', 'destinations.images', 'places', 'places.images', 'travel_agent', 'travel_agent.images', 'images')->has('schedules')->select('tours.*')->join('travel_agencies', 'travel_agencies.id', '=', 'travel_agent_id')->published()->latest('tours.created_at')->limit(30)->get();
         $latest_tours = [];
         foreach ($all_latest_tours as $x) {
             if (!$latest_tours[$x->travel_agent_id] && count($latest_tours) <= 8) {
                 $latest_tours[$x->travel_agent_id] = $x;
             }
         }
         $converted_to_collection = new Collection();
         foreach ($latest_tours as $x) {
             $converted_to_collection->push($x);
         }
         return $converted_to_collection;
     });
     // ------------------------------------------------------------------------------------------------------------
     // TOP DESTINATION
     // ------------------------------------------------------------------------------------------------------------
     $top_destinations = Cache::remember('8_top_destination_in_6_months', 30, function () {
         $destinations = \App\Destination::with('images')->TopDestination(\Carbon\Carbon::now(), \Carbon\Carbon::now()->addMonth(6))->limit(8)->get();
         foreach ($destinations as $k => $v) {
             $destinations[$k]->total_upcoming_schedules;
         }
         return $destinations;
     });
     // ------------------------------------------------------------------------------------------------------------
     // TOTAL UPCOMING TOUR
     // ------------------------------------------------------------------------------------------------------------
     $total_upcoming_tours = Cache::remember('total_upcoming_tour_in_5_years', 60, function () {
         return \App\TourSchedule::scheduledBetween(\Carbon\Carbon::now(), \Carbon\Carbon::now()->addYear(5))->count();
     });
     // ------------------------------------------------------------------------------------------------------------
     // SHOW DISPLAY
     // ------------------------------------------------------------------------------------------------------------
     $this->layout->page = view($this->page_base_dir . 'home');
     $this->layout->page->headlines = $headlines;
     $this->layout->page->homegrids = $homegrids;
     $this->layout->page->latest_tours = $latest_tours;
     $this->layout->page->promo_tours = $promo_tours;
     $this->layout->page->total_upcoming_tours = $total_upcoming_tours;
     $this->layout->page->top_destinations = $top_destinations;
     // 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->place_list = $this->place_list;
     $this->layout->page->tour_shortcut = $this->tour_shortcut;
     //
     $this->layout->title = "Capcus.id - Cari paket tour jadi mudah";
     $this->layout->og['title'] = $this->layout->title;
     $this->layout->og['type'] = 'website';
     $this->layout->og['image'] = asset('images/logo-black.png');
     $this->layout->og['image:type'] = 'image/png';
     $this->layout->og['image:width'] = 275;
     $this->layout->og['image:height'] = 121;
     return $this->layout;
 }
 /**
  * Show the tours page filter by duration.
  *
  * @return \Illuminate\Http\Response
  */
 public function duration($duration)
 {
     // Get number from input string
     $duration = preg_replace("/[^0-9]/", "", $duration);
     $tours = Tour::where('duration', '=', $duration)->published()->get();
     return view('vietnam.duration', ['tours' => $tours, 'duration' => $duration]);
 }
예제 #11
0
 /**
  * Ajax Update the specified to be published or unpublished.
  *
  * @return echo out result
  */
 public function setActiveStatus()
 {
     $data = Input::all();
     if (Request::ajax()) {
         $id = Input::get('id');
         $tour = Tour::find($id);
         $tour->active = $data['active'];
         $tour->update();
         echo $data['active'];
     }
 }
예제 #12
0
 protected function get_latest_tours()
 {
     // ------------------------------------------------------------------------------------------------------------
     // QUERY PAKET TOUR TERBARU
     // ------------------------------------------------------------------------------------------------------------
     $latest_tours = Cache::remember('8_latest_tours_by_different_travel_agent', 30, function () {
         return \App\Tour::with('destinations', 'schedules', 'destinations.images', 'places', 'places.images', 'travel_agent', 'travel_agent.images', 'images')->has('schedules')->select('tours.*')->join('travel_agencies', 'travel_agencies.id', '=', 'travel_agent_id')->published()->latest('tours.created_at')->limit(8)->groupBy('travel_agent_id')->get();
     });
 }
예제 #13
0
 public function eliminartour($id, Request $request)
 {
     Tour::destroy($id);
     return redirect()->back()->with('alert', 'Tour Eliminado con Exito');
 }
예제 #14
0
 /**
  * 
  * @param int $tourId
  * @return $tour
  */
 public function findTour($tourId)
 {
     return Tour::findOrFail($tourId);
 }
예제 #15
-1
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     with(new \App\Tag(['tag' => 'adventure']))->save();
     // DB::enableQueryLog();
     //
     for ($i = 1; $i <= 200; $i++) {
         $destination = \App\Destination::whereNotNull('parent_id')->orderByRaw("RAND()")->first();
         $destination_id = $destination->id;
         // TOUR
         $duration = rand(3, 12);
         $tour = new Tour();
         $tour->fill(['travel_agent_id' => rand(1, 6), 'name' => $duration . 'D/' . ($duration - 1) . 'N ' . $destination->name, 'ittinary' => 'Lorem ipsum Incididunt ut velit voluptate ullamco occaecat ut laboris ad nulla mollit eu Ut sed do dolor sit aliqua amet dolore dolore laboris occaecat ad nulla mollit minim officia voluptate ex et proident dolore cillum dolore do nostrud et exercitation amet commodo magna ex amet sit minim cillum Duis proident amet consequat amet proident fugiat culpa velit qui eu consequat irure nulla consequat sit laborum est deserunt dolore enim id aliquip nisi pariatur pariatur irure tempor in fugiat consectetur ut deserunt Duis tempor dolor dolore laboris ullamco ullamco amet Duis nostrud amet consequat consequat ea non nisi elit cupidatat esse dolor esse exercitation dolor incididunt voluptate dolore nostrud dolor reprehenderit in cupidatat tempor consectetur cupidatat sed dolor amet deserunt cillum occaecat nulla Duis enim consequat enim tempor adipisicing nisi cillum do sed cupidatat reprehenderit Ut.', 'summary' => 'Lorem ipsum Pariatur amet irure labore aute Duis ea irure proident adipisicing adipisicing velit elit in non incididunt ea fugiat exercitation ex enim dolore.', 'duration_day' => $duration, 'duration_night' => $duration - 1, 'published_at' => \Carbon\Carbon::now(), 'slug' => str_slug($duration . 'D/' . ($duration - 1) . 'N ' . $destination->name . ' ' . $i), 'tag_ids' => 1]);
         if (!$tour->save()) {
             dd($tour->getErrors());
         }
         $is_fit = rand(0, 100) < 20;
         // TOUR DESTINATION
         $tour->destinations()->sync([$destination_id]);
         // PLACES
         $places = \App\Place::whereIn('destination_id', $tour->destinations->lists('id'))->limit($tour->duration_day)->orderByRaw('rand()')->get();
         // $queries = DB::getQueryLog();
         // dd(end($queries));
         if ($places->count()) {
             $tour->places()->sync($places->lists('id')->toArray());
         }
         // SCHEDULE
         if (!$is_fit) {
             $departure = \Carbon\Carbon::now()->startOfMonth()->addDay(rand(0, 240));
             $original_price = $duration * rand(1, 10) * 300000;
             $tour->schedules()->saveMany([new \App\TourSchedule(['departure' => $departure, 'departure_until' => \Carbon\Carbon::parse($departure)->addDay(rand(30, 150)), 'currency' => 'IDR', 'original_price' => $original_price, 'discounted_price' => $original_price * (rand(0, 100) <= 20 ? rand(80, 100) / 100 : 1), 'views' => 0])]);
         } else {
             for ($j = 1; $j <= rand(3, 5); $j++) {
                 $departure = \Carbon\Carbon::now()->startOfMonth()->addDay(rand(0, 240));
                 $original_price = $duration * rand(1, 10) * 300000;
                 $tour->schedules()->saveMany([new \App\TourSchedule(['departure' => $departure, 'departure_until' => null, 'currency' => 'IDR', 'original_price' => $original_price, 'discounted_price' => $original_price * (rand(0, 100) <= 20 ? rand(80, 100) / 100 : 1), 'views' => 0])]);
             }
         }
         // OPTIONS
         $tour->options()->sync([1 => ['description' => rand(1, 5)], 3 => ['description' => 'Singapore Airlines'], 5 => ['description' => ''], 6 => ['description' => '']]);
     }
 }