PHPackages                             marshmallow/dataset-country - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. marshmallow/dataset-country

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

marshmallow/dataset-country
===========================

This dataset contains all the countries in the world. They are translateable in different languages. It is also possible to get the flag from said countries. The model is extendable so you can extend and overide all functionality if needed.

v1.3.0(11mo ago)19.0k↓71.9%[1 PRs](https://github.com/marshmallow-packages/dataset-country/pulls)3MITPHPPHP ^7.4|^8.0CI passing

Since Apr 6Pushed 2w ago1 watchersCompare

[ Source](https://github.com/marshmallow-packages/dataset-country)[ Packagist](https://packagist.org/packages/marshmallow/dataset-country)[ Docs](https://github.com/Marshmallow-Development/)[ RSS](/packages/marshmallow-dataset-country/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (16)Used By (3)

[![alt text](https://camo.githubusercontent.com/329958cb02b7bee461fd9dcae7a0a3a34e6595669116ff441ad5ef9e77bc511c/68747470733a2f2f63646e2e6d617273686d616c6c6f772d6f66666963652e636f6d2f6d656469612f696d616765732f6c6f676f2f6d617273686d616c6c6f772e7472616e73706172656e742e7265642e706e67 "marshmallow.")](https://camo.githubusercontent.com/329958cb02b7bee461fd9dcae7a0a3a34e6595669116ff441ad5ef9e77bc511c/68747470733a2f2f63646e2e6d617273686d616c6c6f772d6f66666963652e636f6d2f6d656469612f696d616765732f6c6f676f2f6d617273686d616c6c6f772e7472616e73706172656e742e7265642e706e67)

Marshmallow Dataset Country
===========================

[](#marshmallow-dataset-country)

[![Latest Version on Packagist](https://camo.githubusercontent.com/de1e32a0b3e4cfd47f0ff5d3f279fa5aa7b6fe615727b1dcc96271f069bdca92/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617273686d616c6c6f772f646174617365742d636f756e7472792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marshmallow/dataset-country)[![Total Downloads](https://camo.githubusercontent.com/d087d59acc6ff78a7edeb003f10d813bffd494fba888a1e3dfc101e45dc299ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617273686d616c6c6f772f646174617365742d636f756e7472792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marshmallow/dataset-country)

This dataset contains all the countries in the world. They are translateable in different languages. It is also possible to get the flag from said countries. The model is extendable so you can extend and override all functionality if needed.

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

[](#installation)

Install the package via Composer:

```
composer require marshmallow/dataset-country
```

The service provider is auto-discovered and the package migrations are loaded automatically, so you only need to run your migrations:

```
php artisan migrate
```

This creates a `countries` table with `name`, `slug`, `alpha2` and `alpha3` columns (each unique).

### Seed the table

[](#seed-the-table)

Run the bundled seeder to fill the `countries` table:

```
php artisan db:seed --class="Marshmallow\Datasets\Country\Seeders\CountrySeeder"
```

### Publish the flags

[](#publish-the-flags)

To use the flag images you need to publish them to your local project:

```
php artisan vendor:publish --provider="Marshmallow\Datasets\Country\ServiceProvider" --tag=public --force
```

You can optionally publish the translations as well:

```
php artisan vendor:publish --provider="Marshmallow\Datasets\Country\ServiceProvider" --tag=translations
```

Usage
-----

[](#usage)

The package ships an Eloquent model at `Marshmallow\Datasets\Country\Models\Country`.

```
use Marshmallow\Datasets\Country\Models\Country;

// Look up a country by its ISO alpha-2 code.
$country = Country::alpha2('nl');

// Get all countries ordered by name.
$countries = Country::ordered()->get();
```

### Methods

[](#methods)

- Get the locale (translated) version of a country name with `$country->getNameLocale()`.

### Flags

[](#flags)

You can get the flag of a country with `$country->flag`. If you wish to specify the size of the flag image, you can use `$country->flag(16)`. The available sizes are 16, 24, 32, 48, 64 and 128 (the default is 32). Remember to publish the flags first (see Installation).

### Traits

[](#traits)

Add the `Marshmallow\Datasets\Country\Traits\HasCountry` trait to your models that have a country. This sets up the `country()` relationship:

```
use Marshmallow\Datasets\Country\Traits\HasCountry;

class Address extends Model
{
    use HasCountry;
}

// $address->country instanceof Country
```

### Nova

[](#nova)

Are you using Nova? We have a command for you to generate the Nova Resource. Run `php artisan marshmallow:resource Country Datasets\\Country` and countries will be available to you in Nova. We hide this resource by default in the Nova navigation. If you wish to have it available in the navigation, add `public static $displayInNavigation = true;` to `app/Nova/Country.php`.

### Provinces, cities and airports

[](#provinces-cities-and-airports)

The model also exposes a `provinces()` relationship. This requires the optional [`marshmallow/dataset-google-geotargets`](https://packagist.org/packages/marshmallow/dataset-google-geotargets) package, which provides Google data on provinces, cities, airports etc.

```
composer require marshmallow/dataset-google-geotargets
```

Translations
------------

[](#translations)

The country names are translated into the following languages:

- Arabic (ar)
- Chinese (cn)
- Czech (cs)
- Danish (da)
- German (de)
- Greek (el)
- English (en)
- Spanish (es)
- Estonian (et)
- French (fr)
- Hungarian (hu)
- Italian (it)
- Japanese (ja)
- Lithuanian (lt)
- Dutch (nl)
- Norwegian (no)
- Polish (pl)
- Portuguese (pt)
- Romanian (ro)
- Russian (ru)
- Slovak (sk)
- Thai (th)
- Ukrainian (uk)

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

[](#security-vulnerabilities)

Please report security vulnerabilities by email to  rather than via the public issue tracker.

Credits
-------

[](#credits)

- [Stef](https://marshmallow.dev)
- [All Contributors](https://github.com/marshmallow-packages/dataset-country/contributors)

License
-------

[](#license)

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

---

Copyright (c) 2020 marshmallow

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance77

Regular maintenance activity

Popularity24

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 88.1% 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 ~195 days

Recently: every ~448 days

Total

11

Last Release

331d ago

PHP version history (2 changes)v1.0.0PHP ^7.4

v1.2.1PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/be33d2624e24c516e73892b0929447cc762f3622c024ab8d0d2a59042e5d2c7f?d=identicon)[marshmallow](/maintainers/marshmallow)

---

Top Contributors

[![stefvanesch](https://avatars.githubusercontent.com/u/46725619?v=4)](https://github.com/stefvanesch "stefvanesch (37 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

---

Tags

marshmallow

### Embed Badge

![Health badge](/badges/marshmallow-dataset-country/health.svg)

```
[![Health](https://phpackages.com/badges/marshmallow-dataset-country/health.svg)](https://phpackages.com/packages/marshmallow-dataset-country)
```

PHPackages © 2026

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