rinvex / countries

Rinvex Country is a simple and lightweight package for retrieving country details with flexibility. A whole bunch of data including name, demonym, capital, iso codes, dialling codes, geo data, currencies, flags, emoji, and other attributes for all 250 countries worldwide at your fingertips.
https://rinvex.com
MIT License
1.64k stars 206 forks source link

List all regions #235

Closed sts-ryan-holton closed 1 year ago

sts-ryan-holton commented 1 year ago

Hi, I need to get all of the regions broken down into the following categories:

This is my current approach:

// Europe
$euCountries = \Rinvex\Country\CountryLoader::where('geo.region', 'Europe');

// US/Canada
$usCountries = \Rinvex\Country\CountryLoader::where('geo.region', 'US/Canada');

// Asia/Oceania
$asiaCountries = \Rinvex\Country\CountryLoader::where('geo.region', 'Asia/Oceania');

// Middle East/Africa
$middleEastCountries = \Rinvex\Country\CountryLoader::where('geo.region', 'Middle Ease/Africa');

// Americas
$americasCountries = \Rinvex\Country\CountryLoader::where('geo.region', 'Americas');

return response()->json([
    'all_regions' => \Rinvex\Country\CountryLoader::whereNotNull('geo.region')->count(),
    'eu' => count($euCountries),
    'us' => count($usCountries),
    'aso' => count($asiaCountries),
    'mea' => count($middleEastCountries),
    'sa' => count($americasCountries)
], 200);

I get countries back for Europe and Americas, but not the others. I tried listing regions but nothing shows up?

Omranic commented 1 year ago

Thanks for your question, it’s not returning all results because you’re not calling the right region names.

Checkout data files to see the right names, for example Egypt > Africa https://github.com/rinvex/countries/blob/master/resources/data/eg.json

It might be helpful to get all countries details to see all the regions before splitting, happy coding 🙌