Convert Figma logo to code with AI

antonioribeiro logocountries

Laravel countries and currencies

1,884
297
1,884
70

Top Related Projects

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.

Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CSV, JSON , PHP, SQL and XML formats, in multiple languages and with national flags included; also available are the ISO 3166-2 codes of provinces/ states associated with the countries

:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.

Countries, Languages & Continents data (capital and currency, native name, calling codes).

🌍 Discover our global repository of countries, states, and cities! 🏙️ Get comprehensive data in JSON, SQL, PSQL, SQLSERVER, MONGODB, SQLITE, XML, YAML, and CSV formats. Access ISO2, ISO3 codes, country code, capital, native language, timezones (for countries), and more. #countries #states #cities

Quick Overview

The antonioribeiro/countries repository is a comprehensive Laravel package that provides detailed information about countries, including their names, currencies, languages, and more. It offers a flexible and easy-to-use API for accessing and manipulating country data within Laravel applications.

Pros

  • Extensive dataset with detailed information about countries
  • Easy integration with Laravel applications
  • Regular updates to keep country data current
  • Flexible API for querying and filtering country data

Cons

  • Limited to Laravel framework, not usable in other PHP projects
  • Large dataset may impact performance if not properly optimized
  • Requires manual updates to stay current with the latest country changes

Code Examples

Retrieving all countries:

use PragmaRX\Countries\Package\Countries;

$countries = Countries::all();

Getting a specific country by ISO code:

$country = Countries::where('cca3', 'USA')->first();

Filtering countries by continent:

$europeanCountries = Countries::where('continent.name', 'Europe')->all();

Getting Started

  1. Install the package via Composer:
composer require pragmarx/countries
  1. Add the service provider to your config/app.php file:
'providers' => [
    // ...
    PragmaRX\Countries\Package\ServiceProvider::class,
],
  1. Publish the configuration file:
php artisan vendor:publish --provider="PragmaRX\Countries\Package\ServiceProvider"
  1. Use the package in your Laravel application:
use PragmaRX\Countries\Package\Countries;

$countries = Countries::all();

Competitor Comparisons

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.

Pros of Countries (Rinvex)

  • More comprehensive data, including additional fields like emoji, calling codes, and timezones
  • Regular updates and active maintenance
  • Flexible data retrieval methods, including custom filters and sorting

Cons of Countries (Rinvex)

  • Larger file size due to more extensive data, potentially impacting performance
  • Steeper learning curve for advanced features
  • May require more setup and configuration for basic use cases

Code Comparison

Countries (Antonio Ribeiro):

use PragmaRX\Countries\Package\Countries;

$countries = new Countries();
$country = $countries->where('cca3', 'USA')->first();

Countries (Rinvex):

use Rinvex\Country\Country;

$country = country('us');
$name = $country->getName();
$currency = $country->getCurrency();

Both libraries provide easy access to country data, but Rinvex's Countries offers more detailed information and flexible querying options. Antonio Ribeiro's Countries focuses on simplicity and ease of use for basic country information retrieval. The choice between the two depends on the specific requirements of your project, with Rinvex being more suitable for complex applications needing extensive country-related data.

Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CSV, JSON , PHP, SQL and XML formats, in multiple languages and with national flags included; also available are the ISO 3166-2 codes of provinces/ states associated with the countries

Pros of world_countries

  • Offers data in multiple formats (JSON, XML, CSV, SQL)
  • Includes additional information like country calling codes and TLDs
  • Regularly updated with contributions from the community

Cons of world_countries

  • Less comprehensive data compared to countries
  • Lacks advanced features like currency and language information
  • No built-in integration with frameworks or ORMs

Code Comparison

world_countries (JSON format):

{
    "id": "US",
    "name": "United States",
    "alpha2": "US",
    "alpha3": "USA"
}

countries:

$country = Country::where('cca3', 'USA')->first();
echo $country->name->common;
echo $country->currencies->USD->name;

world_countries provides a simpler data structure, while countries offers more detailed information and integration with Laravel.

Both repositories serve as valuable resources for developers working with country data, but they cater to different needs. world_countries is more suitable for basic country information in various formats, while countries provides a more comprehensive dataset with advanced features and framework integration.

:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.

Pros of country-list

  • Supports a wide range of formats (CSV, JSON, SQL, XML, YAML)
  • Includes country names in multiple languages
  • Regularly updated with contributions from the community

Cons of country-list

  • Limited to basic country information (name, code)
  • Lacks additional data like currencies, timezones, or flags
  • No built-in methods for data manipulation or filtering

Code Comparison

country-list:

$countries = Countries::getList('en', 'json');

countries:

$countries = Countries::all()->toArray();
$countriesJson = Countries::all()->toJson();

Key Differences

  • countries offers more comprehensive data, including currencies, timezones, and geographical information
  • country-list focuses on providing country names and codes in multiple languages and formats
  • countries provides a more robust API for data manipulation and filtering
  • country-list is simpler to use for basic country information needs
  • countries integrates well with Laravel, while country-list is framework-agnostic

Use Cases

  • Use country-list for simple country name and code lookups in multiple languages
  • Choose countries for more complex applications requiring detailed country data and advanced filtering capabilities

Both repositories serve different needs and can be valuable depending on the project requirements and complexity.

Countries, Languages & Continents data (capital and currency, native name, calling codes).

Pros of Countries

  • Lightweight and focused on essential country data
  • Includes additional data like country codes, languages, and currencies
  • Provides data in multiple formats (JSON, CSV, XML)

Cons of Countries

  • Less comprehensive dataset compared to countries
  • Fewer features and customization options
  • Less active development and community support

Code Comparison

Countries:

const countries = require('countries-list');
console.log(countries.countries.US);

countries:

use PragmaRX\Countries\Package\Countries;

$countries = new Countries();
$us = $countries->where('cca3', 'USA')->first();

Key Differences

  • Countries is JavaScript-based, while countries is PHP-based
  • countries offers more extensive data and features
  • Countries focuses on simplicity and essential information
  • countries provides more advanced querying and filtering options

Use Cases

  • Choose Countries for lightweight, basic country data in JavaScript projects
  • Opt for countries when working with PHP and requiring comprehensive country information and advanced features

Community and Maintenance

  • countries has a larger user base and more frequent updates
  • Countries has fewer contributors but maintains a focused scope

🌍 Discover our global repository of countries, states, and cities! 🏙️ Get comprehensive data in JSON, SQL, PSQL, SQLSERVER, MONGODB, SQLITE, XML, YAML, and CSV formats. Access ISO2, ISO3 codes, country code, capital, native language, timezones (for countries), and more. #countries #states #cities

Pros of countries-states-cities-database

  • More comprehensive data, including states and cities
  • Available in multiple formats (JSON, SQL, CSV, XML)
  • Regular updates and contributions from the community

Cons of countries-states-cities-database

  • Larger file size due to more detailed data
  • May require more processing for simple country-only use cases
  • Less integration with Laravel framework

Code Comparison

countries-states-cities-database:

{
  "name": "Afghanistan",
  "iso3": "AFG",
  "iso2": "AF",
  "numeric_code": "004",
  "phone_code": "93",
  "capital": "Kabul",
  "currency": "AFN",
  "currency_name": "Afghan afghani",
  "currency_symbol": "؋",
  "tld": ".af",
  "native": "افغانستان",
  "region": "Asia",
  "subregion": "Southern Asia",
  "timezones": [...]
}

countries:

[
    'name' => 'Afghanistan',
    'cca2' => 'AF',
    'cca3' => 'AFG',
    'ccn3' => '004',
    'cioc' => 'AFG',
    'currency' => ['AFN'],
    'calling_code' => ['93'],
    'capital' => 'Kabul',
    'alt_spellings' => ['AF', 'Afġānistān'],
    'region' => 'Asia',
    'subregion' => 'Southern Asia',
    'languages' => ['prs' => 'Dari', 'pus' => 'Pashto'],
    'translations' => [...],
    'latlng' => [33, 65],
    'demonym' => 'Afghan',
    'landlocked' => true,
    'borders' => ['IRN', 'PAK', 'TKM', 'UZB', 'TJK', 'CHN'],
    'area' => 652230
]

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Countries

World Map

Latest Stable Version License Build Static Analysis

Coverage PHP Downloads StyleCI

What does it gives you?

This package has all sorts of information about countries:

infoitems
taxes32
geometry maps248
topology maps248
currencies256
countries266
timezones423
borders649
flags1,570
states4,526
cities7,376
timezones times81,153

Geology and topology maps

Amongst many other information you'll be able to plot country maps:

Switzerland

Requirements

  • PHP 8.1+
  • Uses Laravel Collections (illuminate/collections) - compatible with Laravel 11 & 12

Version Compatibility

PHPCountriesNotes
< 8.0<= 0.8.2Legacy versions
8.0<= 0.8.3Legacy versions
>= 8.1^1.0Modern PHP with Laravel Collections support

Current version: 1.0.0 - Modern PHP 8.3, 8.4 and 8.5 (alpha) compatibility

What's New in v1.0.0

  • ✅ PHP 8.3, 8.4 and 8.5 (alpha) compatibility
  • ✅ Updated to modern dependency versions
  • ✅ Custom Collection implementation (replaces pragmarx/coollection)
  • ✅ Laravel 10, 11 & 12 support
  • ✅ PHPUnit 10 and 11 support
  • ✅ Maintained full backward compatibility with PHP 8.1

Installing

Use Composer to install it:

composer require pragmarx/countries

Instantiating

use PragmaRX\Countries\Package\Countries;

$countries = new Countries();

echo $countries->where('cca2', 'IT')->first()->hydrateCurrencies()->currencies->EUR->coins->frequent->first();

// or calling it statically

echo Countries::where('cca2', 'IT')->first()->hydrateCurrencies()->currencies->EUR->coins->frequent->first();

Should both return

€1

Overloading the default configuration:

use PragmaRX\Countries\Package\Services\Config;

$countries = new Countries(new Config([
    'hydrate' => [
        'elements' => [
            'currencies' => true,
            'flag' => true,
            'timezones' => true,
        ],
    ],
]));

Usage

This package is not tied to Laravel and doesn't require it to be installed (we have a bridge for this purpose), but it has Laravel Collections in its core, all methods in Collections are available, this way you can do things like filter, map, reduce, search, sort, reject, and a lot more. It, actually, uses Coollection, which is Laravel Collections with a fluent syntax, allowing us to have access to array keys (and values) as object properties.

To get all countries in the data base you just have to:

use PragmaRX\Countries\Package\Countries;

$countries = new Countries();

$all = $countries->all();

To get a json you:

return $countries->toJson();

Filter by keys and values:

$countries->where('name.common', 'Brazil');

Will find Brazil by its common name, which is a

#items: array:22 [▼
  "name" => array:3 [▼
    "common" => "Brazil"
    "official" => "Federative Republic of Brazil"
    "native" => array:1 [▼
      "por" => array:2 [▼
        "official" => "República Federativa do Brasil"
        "common" => "Brasil"
      ]
    ]
  ]

Or alternatively you can filter like this

$countries->whereNameCommon('Brazil');

And, you can go deepeer

$countries->where('name.native.por.common', 'Brasil');

Or search by the country top level domain

$countries->where('tld.0', '.ch');

To get

"name" => array:3 [▼
  "common" => "Switzerland"
  "official" => "Swiss Confederation"
  "native" => array:4 [▶]
]
"tld" => array:1 [▼
  0 => ".ch"
]

And use things like pluck

$countries->where('cca3', 'USA')->first()->hydrateStates()->states->pluck('name', 'postal')->toArray();

To get

"MA" => "Massachusetts"
"MN" => "Minnesota"
"MT" => "Montana"
"ND" => "North Dakota"
...

The package uses a modified Collection which allows you to access properties and methods as objects:

$countries->where('cca3', 'FRA')
         ->first()
         ->borders
         ->first()
         ->name
         ->official;

Should give

Principality of Andorra

Borders hydration is disabled by default, but you can have your borders hydrated easily by calling the hydrate method:

$countries->where('name.common', 'United Kingdom')
         ->hydrate('borders')
         ->first()
         ->borders
         ->reverse()
         ->first()
         ->name
         ->common;

Should return

Ireland

Hydration

To improve performance, hydration, which is enabled by default, can be disable on most country properties, and this is how you manually hydrate properties:

$countries->where('name.common', 'United States')->first()->hydrate('timezones')->timezones->first()->zone_name;

$countries->where('name.common', 'United States')->first()->hydrate('timezones')->timezones->first()->zone_name;

Those are some of the hydratable properties:

  • Borders
  • Cities
  • Currencies
  • Flag
  • Geometry
  • Languages
  • States
  • Taxes
  • Timezone
  • Topology

Extra where rules

Some properties are stored differently and we therefore need special rules for accessing them, these properties are

  • ISO639_3 => The 3 letter language code.
  • ISO4217 => The 3 letter currency code.

You can of course access them like other properties

$countries->whereISO639_3('por')->count();
$countries->where('ISO639_3', 'por')->count();

Mapping

Sometimes you would like to access a property by a different name, this can be done in settings, this way

'maps' => [
    'lca3' => 'ISO639_3'
]

Here we bind the language 3 letter short code ISO format to lca3, which is short for language code alpha 3-letter. So now we can access the property by

$countries->whereLca3('por');

Or

$countries->where('lca3', 'por');

Some other examples from Laravel News and some other contributors

Generate a list of all countries with code, using native name and common

app(PragmaRX\Countries\Package\Countries::class)
->all()
->map(function ($country) {
    $commonName = $country->name->common;

    $languages = $country->languages ?? collect();

    $language = $languages->keys()->first() ?? null;

    $nativeNames = $country->name->native ?? null;

    if (
        filled($language) &&
            filled($nativeNames) &&
            filled($nativeNames[$language]) ?? null
    ) {
        $native = $nativeNames[$language]['common'] ?? null;
    }

    if (blank($native ?? null) && filled($nativeNames)) {
        $native = $nativeNames->first()['common'] ?? null;
    }

    $native = $native ?? $commonName;

    if ($native !== $commonName && filled($native)) {
        $native = "$native ($commonName)";
    }

    return [$country->cca2 => $native];
})
->values()
->toArray();

Should give you 267 (or so) countries like:

"AW" => "Aruba"
"AF" => "افغانستان (Afghanistan)"
"AO" => "Angola"
"AI" => "Anguilla"
"AX" => "Åland (Åland Islands)"
"AL" => "Shqipëria (Albania)"
"AD" => "Andorra"
"AE" => "دولة الإمارات العربية المتحدة (United Arab Emirates)"
"AR" => "Argentina"
"AM" => "Հայաստան (Armenia)"
"AS" => "American Samoa"
"AQ" => "Antarctica"
"TF" => "Terres australes et antarctiques françaises (French Southern and Antarctic Lands)"
"AG" => "Antigua and Barbuda"
"AU" => "Australia"
"AT" => "Österreich (Austria)"
"AZ" => "Azərbaycan (Azerbaijan)"
"BI" => "Burundi"
"BE" => "Belgien (Belgium)"
"BJ" => "Bénin (Benin)"
"BF" => "Burkina Faso"
"BD" => "বাংলাদেশ (Bangladesh)"
"BG" => "България (Bulgaria)"
"BH" => "‏البحرين (Bahrain)"
"BS" => "Bahamas"
"BA" => "Bosna i Hercegovina (Bosnia and Herzegovina)"
"BL" => "Saint-Barthélemy (Saint Barthélemy)"
"SH" => "Saint Helena, Ascension and Tristan da Cunha"
"BY" => "Белару́сь (Belarus)"
"BZ" => "Belize"
"BM" => "Bermuda"
"BO" => "Wuliwya (Bolivia)"
"BQ" => "Caribisch Nederland (Caribbean Netherlands)"
"BR" => "Brasil (Brazil)"
"BB" => "Barbados"
"BN" => "Negara Brunei Darussalam (Brunei)"
"BT" => "འབྲུག་ཡུལ་ (Bhutan)"
"BV" => "Bouvetøya (Bouvet Island)"
"BW" => "Botswana"
"CF" => "République centrafricaine (Central African Republic)"
"CA" => "Canada"
"CC" => "Cocos (Keeling) Islands"
"CH" => "Suisse (Switzerland)"
"CL" => "Chile"
"CN" => "中国 (China)"
"CI" => "Côte d'Ivoire (Ivory Coast)"
"CM" => "Cameroon"
"CD" => "RD Congo (DR Congo)"
"CG" => "République du Congo (Republic of the Congo)"
"CK" => "Cook Islands"
"CO" => "Colombia"
"KM" => "القمر‎ (Comoros)"
"CV" => "Cabo Verde (Cape Verde)"
...

Generate a list of countries

$countries->all()->pluck('name.common')->toArray();

returns

[
    "Aruba",
    "Afghanistan",
    "Angola",
    "Anguilla",
    "Åland Islands",
    ....

Generate a list of currencies

$countries->all()->pluck('currencies')->toArray();

returns

[
  [
    "AWG",
  ],
  [
    "AFN",
  ],
  [
    "AOA",
  ],
  [
    "XCD",
  ],
  [
    "EUR",
  ],
  ....

Get the currency symbol

$countries->where('name.common', 'Brazil')->first()->hydrate('currencies')->currencies->BRL->units->major->symbol;

Generate a list of States

$countries->where('name.common', 'United States')
    ->first()
    ->hydrateStates()
    ->states
    ->sortBy('name')
    ->pluck('name', 'postal');

returns

[
    "AL": "Alabama",
    "AK": "Alaska",
    "AZ": "Arizona",
    "AR": "Arkansas",
    "CA": "California",
    ....
    ....

Hydrate and get a cities

$countries->where('cca3', 'FRA')
    ->first()
    ->hydrate('cities')
    ->cities
    ->paris
    ->timezone;

Should return

Europe/Paris

Get a countries currencies

$countries->where('name.common', 'United States')->first()->currencies;

returns

[{
    "alternativeSigns": [],
    "ISO4217Code": "USD",
    "ISO4217Number": "840",
    "sign": "$",
    "subunits": 100,
    "title": "U.S. dollar",
    ....

Get all currencies

$countries->currencies();

returns

[
    0 => "AED"
    1 => "AFN"
    2 => "ALL"
    3 => "AMD"
    4 => "ANG"
    5 => "AOA"
    6 => "ARS"
    7 => "AUD"
    8 => "AWG"
    9 => "AZN"
    10 => "BAM"
    ....

Get the timezone for a State

return $countries->where('name.common', 'United States')->first()->timezone->NC;

returns

America/New_York

Get all timezones for a country

$countries->where('name.common', 'Brazil')
  ->first()
  ->hydrateTimezones()
  ->timezones
  ->map(function ($timezone) {
      return $timezone->zone_name;
  })->values()
  ->unique()
  ->toArray();

Get all times for a timezone

return $countries->where('name.common', 'United States Virgin Islands')->first()->hydrate('timezones_times')->timezones->first()->times;

returns

"times" => [
    "abbreviation" => "LMT"
    "dst" => "0"
    "gmt_offset" => "-14764"
    "time_start" => "-1825098837"
    "zone_id" => "415"
    1 => [
        "abbreviation" => "AST"
        "dst" => "0"
        "gmt_offset" => "-14400"
        "time_start" => "-1825098836"
        "zone_id" => "415"
    ]
]

Flags

Countries provides many different flag sources, including SVG flags. This is how you use one of the available sources:

Install flag-icon

npm install --save-dev flag-icon-css

Import it to your project

@import '~flag-icon-css/sass/flag-icon.scss';

Use Countries to get the flag span

$unitedStatesFlag =
    $this->countries->where('cca3', 'USA')
    ->first()
    ->flag
    ->flag_icon;

Render it in your blade template

{!! $unitedStatesFlag !!}

Publishing assets

You can publish configuration by doing:

php artisan vendor:publish --provider=PragmaRX\\Countries\\ServiceProvider

Data

Sources

This package uses some other open source packages and, until we don't build a better documentation, you can find some more info about data on mledoze/countries and how to use it on this fantastic Laravel News article.

Please check the copyright section for a complete list of packages used by this one.

Updating

WARNING

No data files (JSON, images, icons...) on this project can be updated manually. We will close all pull requests requiring manual updates to those files will be closed, because the update script will delete them anyway.

If you find something wrong with data, you, please, have to ask the package managers (listed data sources and on the copyright section) to fix them, and then you can yourself run the update script to properly update them on this repository.

update.php

This package comes with the update.php script, which you MUST use to update the data files. It will download all info from all packages and automatically build the .json (and some others like .svg too). This is how you do it:

cd vendor/pragmarx/countries
composer install
php update.php

And wait for a very long time* (sometimes it looks like stuck but it's not) until it finishes rebuilding everything, then it's just a matter of staging, commit, push all regenerated files, and draft a new PR.

Cache

Since this data is not supposed to change, calls are automatically cached. If you want to change this behaviour, you can edit config/countries.php file once it's published.

Framework bridges

Sample files

Author

Antonio Carlos Ribeiro All contributors

Copyright

To build the countries database and relations, this package make use of those sources and packages:

License

Countries is licensed under the BSD 3-Clause License - see the LICENSE file for details

Contributing

Pull requests and issues are more than welcome.