error('Missing storage/app/cities.json file!'); return; } if(Place::count() > 10) { $this->error('Cities already imported, aborting operation...'); return; } $this->info('Importing city data into database ...'); $cities = file_get_contents($path); $cities = json_decode($cities); $count = count($cities); $this->info("Found {$count} cities to insert ..."); $bar = $this->output->createProgressBar($count); $bar->start(); foreach ($cities as $city) { $country = $city->country == 'XK' ? 'Kosovo' : (new \League\ISO3166\ISO3166)->alpha2($city->country)['name']; DB::transaction(function () use ($city, $country) { $place = new Place(); $place->name = $city->name; $place->slug = Str::slug($city->name); $place->country = $country; $place->lat = $city->lat; $place->long = $city->lng; $place->save(); }); $bar->advance(); } $bar->finish(); return; } }