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.65k stars 206 forks source link

Get country codes by region #234

Closed sts-ryan-holton closed 1 year ago

sts-ryan-holton commented 1 year ago

Hi,

I'm developing a Laravel application based on SMS messaging. My application allows users to send messages to different regions, for example, Europe, Worldwide, US/Canada, Americas etc...

Does this package support fetching all country codes by a region?

For example:

EUR would fetch me all of the country codes for this region, which I could then, when validating a phone number check the country code exists.

Again, I'm evaluating whether I can install and invest some time into this package.

Omranic commented 1 year ago

Hey @sts-ryan-holton, thanks for the good question.

Yep, you can do that using a couple of ways, for example:

// Get countries with where condition (continent: Europe)
$euCountries = \Rinvex\Country\CountryLoader::where('geo.continent', ['EU' => 'Europe']);

// Or get countries with where condition (region: Europe)
$euCountries2 = \Rinvex\Country\CountryLoader::where('geo.region', 'Europe');

Check here a couple more usage examples https://github.com/rinvex/countries#usage