PHPackages                             cyberionsys/laravel-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. cyberionsys/laravel-countries

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

cyberionsys/laravel-countries
=============================

A database with ISO country information in all configured translations

v2.0.0(2y ago)0339[3 PRs](https://github.com/cyberionsys/laravel-countries/pulls)MITPHPPHP ^8.1

Since Dec 23Pushed 1y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (16)Versions (6)Used By (0)

Laravel Countries
=================

[](#laravel-countries)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cf4fa0e59553fa0a163e5e9a2a9b11ff2fa505baa121f90fa030f2623863b6b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6379626572696f6e7379732f6c61726176656c2d636f756e74726965732e7376673f6c6162656c3d56657273696f6e)](https://packagist.org/packages/cyberionsys/laravel-countries)[![GitHub Tests Action Status](https://github.com/cyberionsys/laravel-countries/workflows/Tests/badge.svg?branch=main)](https://github.com/cyberionsys/laravel-countries/actions?query=workflow%3ATests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/bffa14b00b1e19761f273269631b4f3e0a35068907d0c7dd3b1cd266035d20cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6379626572696f6e7379732f6c61726176656c2d636f756e74726965732e7376673f6c6162656c3d446f776e6c6f616473)](https://packagist.org/packages/cyberionsys/laravel-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 cyberionsys/laravel-countries
```

The latest version of this package requires PHP version 8.1 or above.

### Migrations

[](#migrations)

Optionally, you can publish the database migrations with:

```
php artisan vendor:publish --provider="Cyberionsys\Countries\CountriesServiceProvider" --tag="countries-migrations"
```

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).

### Config

[](#config)

Optionally, you can publish the config file with:

```
php artisan vendor:publish --provider="Cyberionsys\Countries\CountriesServiceProvider" --tag="countries-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',
    ],
];
```

After making changes to the config you need to re-migrate your database:

> **Warning**This will recreate your entire database. Please take appropriate cautions before running it

```
php artisan migrate:refresh
```

Usage
-----

[](#usage)

### Country model

[](#country-model)

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

Cyberionsys\Countries\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)

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

Cyberionsys\Countries\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');

Cyberionsys\Countries\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: [
       Cyberionsys\Countries\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",
       },
       Cyberionsys\Countries\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",
       },
       Cyberionsys\Countries\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):
Cyberionsys\Countries\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 Cyberionsys\Countries\Casts\AsCurrency;

class MyModel{

    // ...

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

    // ...
}

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

Cyberionsys\Countries\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' => Cyberionsys\Countries\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)

- [Cyberion Systems](https://github.com/cyberionsys)
- Original idea from [Martin](https://github.com/io238)
-
-
-
-
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~230 days

Total

2

Last Release

1006d ago

Major Versions

v1.0.0 → v2.0.02023-08-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/020364c0e401a49cd5e396c712a8a8f671905613f989d02d55fff72ae063808d?d=identicon)[cyberionsys](/maintainers/cyberionsys)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 commits)")[![mlniang](https://avatars.githubusercontent.com/u/25245717?v=4)](https://github.com/mlniang "mlniang (2 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (2 commits)")

---

Tags

phplaravellanguageseloquentcountriesisoworldcurrenciescastcodescountry codesIso3166iso4217iso639-1custom-castsLaravel-Countriescyberionsys

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[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.

5462.3k](/packages/io238-laravel-iso-countries)[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17649.9k](/packages/lacodix-laravel-model-filter)[juanparati/iso-codes

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

17146.4k](/packages/juanparati-iso-codes)[kiwilan/typescriptable-laravel

PHP package for Laravel to type Eloquent models, routes, Spatie Settings with autogenerated TypeScript. If you want to use some helpers with Inertia, you can install associated NPM package.

3920.9k](/packages/kiwilan-typescriptable-laravel)[giacomomasseron/laravel-models-generator

Generate Laravel models from an existing database

484.2k](/packages/giacomomasseron-laravel-models-generator)

PHPackages © 2026

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