コード例 #1
0
 public function getReservations()
 {
     if (Input::has('st_date')) {
         $st_date = Input::get('st_date');
     } elseif (Session::has('st_date')) {
         $st_date = Session::get('st_date');
     } else {
         $st_date = date("Y/m/d");
     }
     //Session::flush();
     if (Input::has('ed_date')) {
         $ed_date = Input::get('ed_date');
     } elseif (Session::has('ed_date')) {
         $ed_date = Session::get('ed_date');
     } else {
         $ed_date = date("Y/m/d", strtotime($st_date . ' + 2 days'));
     }
     //    dd($st_date);
     Session::put('st_date', $st_date);
     Session::put('ed_date', $ed_date);
     if (Input::has('txt-search')) {
         $get_city_or_hotel = Input::get('txt-search');
         Session::put('reservation', 2);
         Session::put('txt-search', $get_city_or_hotel);
     } else {
         if (Session::has('txt-search')) {
             $get_city_or_hotel = Session::get('txt-search');
         } else {
             $get_city_or_hotel = 'Kandy';
         }
         Session::put('reservation', 3);
     }
     if (Input::has('availability')) {
         if (Input::has('room_type')) {
             $room_type = Input::get('room_type');
         } else {
             $room_type = 2;
         }
         if (Input::has('meal_basis')) {
             $meal_basis = Input::get('meal_basis');
         } else {
             $meal_basis = 2;
         }
         if (Input::has('room_count')) {
             $room_count = Input::get('room_count');
         } else {
             $room_count = 1;
         }
     } else {
         $room_type = '%';
         $meal_basis = '%';
         $room_count = 1;
     }
     // dd($room_type.'/'.$meal_basis);
     Session::put('room_type', $room_type);
     Session::put('meal_basis', $meal_basis);
     Session::put('room_count', $room_count);
     if (Input::has('hotel_star')) {
         Session::put('reservation', 2);
         $star = Input::get('hotel_star');
         if ($star == 4) {
             $star = 5;
         } else {
             if ($star == 5) {
                 $star = 7;
             }
         }
     } else {
         $star = '%';
     }
     Session::put('reservation', 2);
     if (!empty($get_city_or_hotel)) {
         $city_or_hotel = $get_city_or_hotel;
         $get_city_or_hotel_id = DB::table('cities')->where('city', 'LIKE', $city_or_hotel)->where('val', 1)->first();
         if (!is_null($get_city_or_hotel_id)) {
             $city_id = $get_city_or_hotel_id->id;
             //dd($city_id);
             $hotels = Rate::With('MealBasis', 'RoomSpecification', 'Hotel')->WhereHas('Hotel', function ($q) use($city_id, $star) {
                 $q->where('val', 1);
                 $q->where('star_category_id', 'LIKE', $star);
                 $q->where('city_id', $city_id);
             })->where('room_specification_id', 'LIKE', $room_type)->where('meal_basis_id', 'LIKE', $meal_basis)->groupBy('hotel_id')->orderBy('hotel_id', 'desc')->paginate(9);
             //dd($hotels);
         } else {
             $get_city_or_hotel_id = DB::table('hotels')->where('name', 'LIKE', $city_or_hotel)->first();
             $hotel_id = $get_city_or_hotel_id->id;
             $city_id = $get_city_or_hotel_id->city_id;
             $get_city = DB::table('cities')->where('id', '=', $city_id)->first();
             $city_name = $get_city->city;
             $hotels = Rate::WhereHas('Hotel', function ($q) use($hotel_id) {
                 $q->where('val', 1);
                 $q->where('hotel_id', $hotel_id);
             })->groupBy('hotel_id')->paginate(5);
         }
     }
     return View::make('reservations.index')->with(array('hotels' => $hotels, 'city_or_hotel' => $city_or_hotel, 'st_date' => $st_date, 'ed_date' => $ed_date));
 }