PHPackages                             io238/laravel-iso-countries - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. io238/laravel-iso-countries

ActiveLibrary[Database &amp; ORM](/categories/database)

io238/laravel-iso-countries
===========================

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

1.4.1(1mo ago)5462.3k↓29.8%14[3 issues](https://github.com/io238/laravel-iso-countries/issues)MITPHPPHP ^8.1CI passing

Since Dec 28Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/io238/laravel-iso-countries)[ Packagist](https://packagist.org/packages/io238/laravel-iso-countries)[ Docs](https://github.com/io238/laravel-iso-countries)[ RSS](/packages/io238-laravel-iso-countries/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (22)Versions (20)Used By (0)

Laravel ISO Countries
=====================

[](#laravel-iso-countries)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5692f17c28b99802576fc5e2173f3799584ad419f2ee4d922050aa2ef97b76ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696f3233382f6c61726176656c2d69736f2d636f756e74726965732e7376673f6c6162656c3d56657273696f6e)](https://packagist.org/packages/io238/laravel-iso-countries)[![GitHub Tests Action Status](https://github.com/io238/laravel-iso-countries/workflows/Tests/badge.svg?branch=main)](https://github.com/io238/laravel-iso-countries/actions?query=workflow%3ATests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/9093a00ee9770665b62dff3830d646291afda87e8a0e3136b6dc608b9af4fe04/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696f3233382f6c61726176656c2d69736f2d636f756e74726965732e7376673f6c6162656c3d446f776e6c6f616473)](https://packagist.org/packages/io238/laravel-iso-countries)

This package provides ready-to-use application models and seeds the database with ISO data from various sources. This package can be used in multi-language apps and supports Country/Language/Currency names in almost any locale.

### Included datasets

[](#included-datasets)

- [Countries: ISO 3166 alpha 2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (incl. names, capital, lat/lon coordinates, TLD, phone calling code, regions, population, gini, area)
- [Languages: ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) (incl. names, language-family, wiki link)
- [Currencies: ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) (incl. names, symbol, decimal digits, rounding)

Unlike other packages, this one also includes relevant data relationships, such as:

```
// Official languages spoken in Luxembourg ('LU')
Country::find('LU')->languages;

// Currencies used in Ghana ('GH')
Country::find('GH')->currencies;

// Countries that have Spanish ('es') as one of their official languages
Language::find('es')->countries;

// Countries that use the Euro ('EUR') as currency
Currency::find('EUR')->countries;
```

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require io238/laravel-iso-countries
```

### Version support

[](#version-support)

Package versionLaravel versionsPHP versions`1.4.x``8` to `13``8.1+``1.3.x``8` to `12``8.1+``1.2.x``7` to `10``8.1+``1.1.3``7` to `9``7.4+``1.0.0` to `1.1.2``8``7.4+``0.2.x``8``7.4+`Notes:

- The package's own minimum PHP version is shown above, but newer Laravel versions may require a higher PHP version.
- In practice that means Laravel `12` requires PHP `8.2+`, and Laravel `13` requires PHP `8.3+`.
- Older `1.2.x` and `1.1.x` releases include Laravel `7` in their composer constraints. `1.3.x` and later only verify Laravel `8+` in CI.

### Migrations

[](#migrations)

There is no need to run any migrations. All country data information is stored in a pre-compiled SQLITE database that is stored within this package.

By default, this database includes all country/language/&amp;currency names translated into English, German, French, and Spanish. If you want to compile your own database with other languages, please [see the instructions here](#data-updates--translations).

### Rebuilding the database

[](#rebuilding-the-database)

Country-level ISO data does not change very often. Nevertheless, if at any time you want to update the ISO data to the latest available version, you can manually re-seed the tables:

### Config

[](#config)

Optionally, you can publish the config file with:

```
php artisan vendor:publish --provider="Io238\ISOCountries\ISOCountriesServiceProvider" --tag="config"
```

In the config you can define, which translations of country/language/currency names you want to store in your DB.

This is the contents of the published config file:

```
[
    // Supported locales for names (countries, languages, currencies)
    'locales' => [
        'en',
        'de',
        'fr',
        'es',
    ],

    // Path for storing your own SQLITE database
    'database_path' => database_path('iso-countries.sqlite'),
];
```

After making changes to the config you need to re-build the database with the following command:

```
php artisan db:seed countries:build
```

This will create a new SQLITE database and stores it in your project at `database/iso-countries.sqlite`. Exclude this file from `.gitignore` to have it available in all environments.

```
# database/.gitignore

*.sqlite*
!iso-countries.sqlite
```

Usage
-----

[](#usage)

### Country model

[](#country-model)

```
Country::find('AD');

Io238\ISOCountries\Models\Country {
     id: "AD",
     alpha3: "AND",
     name: "{"en":"Andorra","de":"Andorra","fr":"Andorre","es":"Andorra"}",
     native_name: "Andorra",
     capital: "Andorra la Vella",
     top_level_domain: ".ad",
     calling_code: "376",
     region: "Europe",
     subregion: "Southern Europe",
     population: 78014,
     lat: 42.5,
     lon: 1.5,
     demonym: "Andorran",
     area: 468,
   }
```

### Language model

[](#language-model)

```
Country::find('pt');

Io238\ISOCountries\Models\Language {
     id: "pt",
     iso639_2: "por",
     iso639_2b: null,
     name: "{"en":"Portuguese","de":"Portugiesisch","fr":"portugais","es":"portugu\u00e9s"}",
     native_name: "Português",
     family: "Indo-European",
     wiki_url: "https://en.wikipedia.org/wiki/Portuguese_language",
   }
```

### Currency model

[](#currency-model)

```
Currency::find('COP');

Io238\ISOCountries\Models\Currency {
     id: "COP",
     name: "{"en":"Colombian Peso","de":"Kolumbianischer Peso","fr":"peso colombien","es":"peso colombiano"}",
     name_plural: "Colombian pesos",
     symbol: "CO$",
     symbol_native: "$",
     decimal_digits: 0,
     rounding: 0,
   }
```

### Query relationships

[](#query-relationships)

All models have pre-defined many-to-many relationships that can be queried:

```
// Retrieve languages that are spoken in Luxembourg
Country::find('LU')->languages;

Illuminate\Database\Eloquent\Collection {
     all: [
       Io238\ISOCountries\Models\Language {
         id: "de",
         iso639_2: "deu",
         iso639_2b: "ger",
         name: "{"en":"German","de":"Deutsch","fr":"allemand","es":"alem\u00e1n"}",
         native_name: "Deutsch",
         family: "Indo-European",
         wiki_url: "https://en.wikipedia.org/wiki/German_language",
       },
       Io238\ISOCountries\Models\Language {
         id: "fr",
         iso639_2: "fra",
         iso639_2b: "fre",
         name: "{"en":"French","de":"Franz\u00f6sisch","fr":"fran\u00e7ais","es":"franc\u00e9s"}",
         native_name: "français, langue française",
         family: "Indo-European",
         wiki_url: "https://en.wikipedia.org/wiki/French_language",
       },
       Io238\ISOCountries\Models\Language {
         id: "lb",
         iso639_2: "ltz",
         iso639_2b: null,
         name: "{"en":"Luxembourgish","de":"Luxemburgisch","fr":"luxembourgeois","es":"luxemburgu\u00e9s"}",
         native_name: "Lëtzebuergesch",
         family: "Indo-European",
         wiki_url: "https://en.wikipedia.org/wiki/Luxembourgish_language",
       },
     ],
   }
```

```
// Retrieve all countries that use the Euro (EUR) as currency.
Currency::find('EUR')->countries->pluck('name');

Illuminate\Support\Collection {
     all: [
       "Andorra",
       "Austria",
       "Åland Islands",
       "Belgium",
       "St. Barthélemy",
       "Cyprus",
       "Germany",
       "Estonia",
       "Spain",
       "Finland",
       "France",
       "French Guiana",
       "Guadeloupe",
       "Greece",
       "Ireland",
       "Italy",
       "Lithuania",
       "Luxembourg",
       "Latvia",
       "Monaco",
       "Montenegro",
       "St. Martin",
       "Martinique",
       "Malta",
       "Netherlands",
       "St. Pierre & Miquelon",
       "Portugal",
       "Réunion",
       "Slovenia",
       "Slovakia",
       "San Marino",
       "French Southern Territories",
       "Vatican City",
       "Republic of Kosovo",
       "Mayotte",
       "Zimbabwe",
     ],
   }
```

### Localized names

[](#localized-names)

Each of the package models (Country, Language, Currency) has a `->name` attribute, which will be displayed in the app's locale, using the [spatie/laravel-translatable](https://github.com/spatie/laravel-translatable) package. The default config will migrate localized names for `en`, `de`, `fr`, and `es`. This can be adjusted in the [config](#config). The config `app.locale` and `app.fallback_locale` are automatically included.

```
// Set the app locale
app()->setLocale('fr');

// Retrieve the top 10 countries in Africa (by population):
Io238\ISOCountries\Models\Country::where('region', 'Africa')->orderByDesc('population')->limit(10)->pluck('name');

// Country names will be returned according to the app locale (fr = French)
Illuminate\Support\Collection {
     all: [
       "Nigéria",
       "Éthiopie",
       "Égypte",
       "Congo-Kinshasa",
       "Afrique du Sud",
       "Tanzanie",
       "Kenya",
       "Algérie",
       "Soudan",
       "Ouganda",
     ],
   }
```

### Attribute casting

[](#attribute-casting)

If you already use ISO codes in your models, you can enrich them by casting them as Country/Language/Currency model:

```
use Io238\ISOCountries\Casts\Currency;

class MyModel{

    // ...

    protected $casts = [
        'currency' => Currency::class,
    ];

    // ...
}

// Now you can dynamically retrieve all meta data associated with the currency
MyModel::first()->currency;

Io238\ISOCountries\Models\Currency {
     id: "JPY",
     name: "{"en":"Japanese Yen","de":"Japanischer Yen","fr":"yen japonais","es":"yen"}",
     name_plural: "Japanese yen",
     symbol: "¥",
     symbol_native: "￥",
     decimal_digits: 0,
     rounding: 0,
   }

// When filling the model, the ISO code (string) or the model can be used
MyModel::first()->update(['currency' => 'USD']);
MyModel::first()->update(['currency' => Io238\ISOCountries\Models\Currency::find('USD')]);
```

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [io238](https://github.com/io238)
- [azakhozhiy](https://github.com/azakhozhiy)
-
-
-
-
-
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance88

Actively maintained with recent releases

Popularity45

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 98% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~191 days

Recently: every ~369 days

Total

11

Last Release

54d ago

Major Versions

0.2.0 → 1.0.02020-12-29

PHP version history (2 changes)0.1.0PHP ^7.4|^8.0

1.2.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/5dba54660f9b9a054f9779084ce5c3a67f799e2be6829e37d9c1275aabf8e41c?d=identicon)[io238](/maintainers/io238)

---

Top Contributors

[![io238](https://avatars.githubusercontent.com/u/26689138?v=4)](https://github.com/io238 "io238 (98 commits)")[![azakhozhiy](https://avatars.githubusercontent.com/u/14373063?v=4)](https://github.com/azakhozhiy "azakhozhiy (1 commits)")[![tomcoonen](https://avatars.githubusercontent.com/u/988013?v=4)](https://github.com/tomcoonen "tomcoonen (1 commits)")

---

Tags

castcodescountriescountry-codescurrencycustom-castseloquentisoiso3166iso4217iso639-1languageslaravelphpworldphplaravellanguageseloquentcountriesisoworldcurrenciescastcodescountry codesIso3166iso4217iso639-1custom-casts

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/io238-laravel-iso-countries/health.svg)

```
[![Health](https://phpackages.com/badges/io238-laravel-iso-countries/health.svg)](https://phpackages.com/packages/io238-laravel-iso-countries)
```

###  Alternatives

[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[sebastiaanluca/laravel-boolean-dates

Automatically convert Eloquent model boolean attributes to dates (and back).

40111.7k1](/packages/sebastiaanluca-laravel-boolean-dates)[juanparati/iso-codes

A PHP library that provides ISO codes, currencies, languages, timezones and additional geopolitical information

17146.4k](/packages/juanparati-iso-codes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
