Ejemplo n.º 1
0
 /**
  * Show cities list.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function cities($country_code, $region_id)
 {
     $cities = City::active()->orderBy('name', 'ASC')->whereHas('country', function ($query) {
         $query->active();
     })->whereHas('region', function ($query) {
         $query->active();
     })->byCountryCode($country_code)->byRegion($region_id)->get(['id', 'country_code', 'name', 'slug']);
     return response()->json(['cities' => $cities]);
 }
Ejemplo n.º 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Country::create($this->country());
     Region::insert($this->regions());
     if ($this->cities() > 4000) {
         foreach (array_chunk($this->cities(), 3500) as $chunk) {
             City::insert($chunk);
         }
     } else {
         City::insert($this->cities());
     }
 }
Ejemplo n.º 3
0
 /**
  * Check if country is already installed.
  *
  * @param  string $country
  * @return boolean
  */
 public static function installed($country)
 {
     $seeder = self::loadSeeder($country);
     $country = $seeder->country();
     if (Country::where('code', $country['code'])->count() > 0) {
         return true;
     }
     if (Region::where('country_code', $country['code'])->count() > 0) {
         return true;
     }
     if (City::where('country_code', $country['code'])->count() > 0) {
         return true;
     }
     return false;
 }