/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $allusers = User::all();
     $url = "https://randomapi.com/api/?key=" . env('RANDOMAPI_API_KEY') . "&id=6tnf0qn&results=50";
     $json = file_get_contents($url);
     $json_data = json_decode($json, true);
     $types = ['private_room', 'shared_room', 'entire_place'];
     foreach ($json_data['results'] as $result) {
         $result = $result['object'];
         $property = new Property();
         $property->title = $result['title'];
         $oneuser = $allusers[rand(0, count($allusers) - 1)];
         $property->owner_id = $oneuser->id;
         $property->address = explode(" | ", $result['address'])[2];
         $all_cities = City::all();
         $property->city_id = $all_cities[rand(0, count($all_cities) - 1)]->id;
         $valid_districts = District::where('city_id', $property->city_id)->get();
         $property->district_id = $valid_districts[rand(0, count($valid_districts) - 1)]->id;
         $property->type = $types[array_rand($types)];
         $property->price_per_night = rand(20, 1333);
         $property->max_occupancy = rand(1, 6);
         $property->description = 'A charming ' . $result['title'];
         $property->save();
         $features = new PropertyFeatures();
         $features->property_id = $property->id;
         $features->kitchen = rand(0, 1) == 1;
         $features->internet = rand(0, 1) == 1;
         $features->tv = rand(0, 1) == 1;
         $features->essentials = rand(0, 1) == 1;
         $features->shampoo = rand(0, 1) == 1;
         $features->heating = rand(0, 1) == 1;
         $features->air_conditioning = rand(0, 1) == 1;
         $features->washer = rand(0, 1) == 1;
         $features->dryer = rand(0, 1) == 1;
         $features->free_parking_on_premises = rand(0, 1) == 1;
         $features->wireless_internet = rand(0, 1) == 1;
         $features->cable_tv = rand(0, 1) == 1;
         $features->breakfast = rand(0, 1) == 1;
         $features->pets_allowed = rand(0, 1) == 1;
         $features->family_kid_friendly = rand(0, 1) == 1;
         $features->suitable_for_events = rand(0, 1) == 1;
         $features->smoking_allowed = rand(0, 1) == 1;
         $features->wheelchair_accessible = rand(0, 1) == 1;
         $features->elevator_in_building = rand(0, 1) == 1;
         $features->indoor_fireplace = rand(0, 1) == 1;
         $features->buzzer_wireless_intercom = rand(0, 1) == 1;
         $features->doorman = rand(0, 1) == 1;
         $features->pool = rand(0, 1) == 1;
         $features->hot_tub = rand(0, 1) == 1;
         $features->gym = rand(0, 1) == 1;
         $features->feature_24_hour_check_in = rand(0, 1) == 1;
         $features->hangers = rand(0, 1) == 1;
         $features->iron = rand(0, 1) == 1;
         $features->hair_dryer = rand(0, 1) == 1;
         $features->laptop_friendly_workspace = rand(0, 1) == 1;
         $features->save();
     }
 }
Example #2
0
     $features->suitable_for_events = on2true($request->get('suitable_for_events', false));
     $features->smoking_allowed = on2true($request->get('smoking_allowed', false));
     $features->wheelchair_accessible = on2true($request->get('wheelchair_accessible', false));
     $features->elevator_in_building = on2true($request->get('elevator_in_building', false));
     $features->indoor_fireplace = on2true($request->get('indoor_fireplace', false));
     $features->buzzer_wireless_intercom = on2true($request->get('buzzer_wireless_intercom', false));
     $features->doorman = on2true($request->get('doorman', false));
     $features->pool = on2true($request->get('pool', false));
     $features->hot_tub = on2true($request->get('hot_tub', false));
     $features->gym = on2true($request->get('gym', false));
     $features->feature_24_hour_check_in = on2true($request->get('feature_24_hour_check_in', false));
     $features->hangers = on2true($request->get('hangers', false));
     $features->iron = on2true($request->get('iron', false));
     $features->hair_dryer = on2true($request->get('hair_dryer', false));
     $features->laptop_friendly_workspace = on2true($request->get('laptop_friendly_workspace', false));
     $features->save();
     return redirect(url('property'));
 });
 Route::delete('/property/{property}', function (Property $property) {
     $property->delete();
     return redirect(url('property'));
 });
 Route::post('/property/request_booking/', array('middleware' => 'auth', function (Request $request) {
     $data = $request->all();
     $validator = Validator::make($request->all(), ['check_in' => 'required|after:yesterday|date', 'check_out' => 'required|after:check_in|date', 'property_id' => 'required|numeric|integer|min:0']);
     if ($validator->fails()) {
         return redirect(url('/property/' . $data['property_id']))->withInput()->withErrors($validator);
     }
     $property_id = $data['property_id'];
     $select_statement = 'SELECT * FROM bookings WHERE ' . "'" . $data['check_in'] . "'" . ' <= bookings.end AND ' . "'" . $data['check_out'] . "'" . ' >= START AND bookings.status = ' . "'" . 'confirmed' . "'" . 'AND bookings.property_id = ' . $property_id;
     $overlapping_bookings = DB::select($select_statement);