khsing / laravel-world

provide countries, states, and cities relations and database.
MIT License
431 stars 90 forks source link

!!!!BUG!!!!!! #41

Closed officialmmt closed 3 years ago

officialmmt commented 3 years ago

World::getByCode('abd') not working with cities codes! I really need it. Can you fix it soon?

khsing commented 3 years ago

@officialmmt if you want World::getByCode direct to city level, you have to pass country code first, e.g. World::getByCode('cn-11') is Beijing, China

officialmmt commented 3 years ago

I am asking from start. How I can get City information with city code???

khsing commented 3 years ago

@officialmmt there is no way to get city information without country code, either you get a country model first and filter children() or pass a country code with city code.

// get country model first 
$country = World::getByCode('cm');
$country->children()->where('code','sou')->first();
=> Khsing\World\Models\City {#3224
     id: 1049,
     country_id: 1,
     division_id: null,
     name: "Sud-Oueste",
     full_name: null,
     code: "sou",
     +local_name: "Sud-Oueste",
     +local_full_name: null,
     +local_alias: "Sud-Oueste",
     +local_abbr: "Sud-Oueste",
   }

// get city directly
$city = World::getByCode('cm-sou');

// or you can get through model
use Khsing\World\Models\City;
City::where('code','sou')->first();
officialmmt commented 3 years ago

Oh I didn't find that. Thank you for fast answers. Have a nice day!