/** * 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(); } }
array_push($myErrorArr, 'That city is not recognized.'); } if (count($myErrorArr) > 0) { return redirect(url('/property/add'))->withInput()->withErrors($myErrorArr); } $property = Property::find($data['property_id']); $property->title = $request->title; $property->address = $request->address; $property->district_id = $districts[0]->id; $property->city_id = $cities[0]->id; $property->type = $request->type; $property->price_per_night = $request->price_per_night; $property->max_occupancy = $request->max_occupancy; $property->description = $request->description; $property->save(); $features = PropertyFeatures::where('property_id', $property->id)->get()[0]; $features->property_id = $property->id; $features->kitchen = on2true($request->get('kitchen', false)); $features->internet = on2true($request->get('internet', false)); $features->tv = on2true($request->get('tv', false)); $features->essentials = on2true($request->get('essentials', false)); $features->shampoo = on2true($request->get('shampoo', false)); $features->heating = on2true($request->get('heating', false)); $features->air_conditioning = on2true($request->get('air_conditioning', false)); $features->washer = on2true($request->get('washer', false)); $features->dryer = on2true($request->get('dryer', false)); $features->free_parking_on_premises = on2true($request->get('free_parking_on_premises', false)); $features->wireless_internet = on2true($request->get('wireless_internet', false)); $features->cable_tv = on2true($request->get('cable_tv', false)); $features->breakfast = on2true($request->get('breakfast', false)); $features->pets_allowed = on2true($request->get('pets_allowed', false));