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

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

altwaireb/laravel-countries
===========================

Laravel Countries , Countries States Cities DB Migration &amp; Seeder

1.1.0(11mo ago)273.2k↓23.8%[3 PRs](https://github.com/altwaireb/laravel-countries/pulls)MITPHPPHP ^8.2CI passing

Since May 29Pushed 4mo agoCompare

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

READMEChangelog (4)Dependencies (13)Versions (8)Used By (0)

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

[](#laravel-countries)

This package allows you to add all Countries, States, and Cities data with DB Migration &amp; Seeder for Laravel.

[![Latest Version on Packagist](https://camo.githubusercontent.com/b4ff0147d3e3d8075a8bb56a77a8f183a0fa902e6cb75c6b26f4460303337ddc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c747761697265622f6c61726176656c2d636f756e74726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/altwaireb/laravel-countries)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b206c642a57bc6524951a1edce36801fb481bfb9b51398318b5239b9954a7d6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c747761697265622f6c61726176656c2d636f756e74726965732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/altwaireb/laravel-countries/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/1a5b88af86ce82beedbcb3a4fb81150a2bc3953ded4bff1c0d920a51941d09cc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c747761697265622f6c61726176656c2d636f756e74726965732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/altwaireb/laravel-countries/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/bb5b63e8102d830ad542376d38cf1fff611e4b60854ee36c1a9283f556691264/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c747761697265622f6c61726176656c2d636f756e74726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/altwaireb/laravel-countries)

Numbers
-------

[](#numbers)

ModelNumber of itemsCountry250State4961City148059Attributes
----------

[](#attributes)

Common attributes:

- `name`: Common name of Country(english).
- `iso2`: ISO-3166-2 code.
- `iso2`: ISO-3166-3 code.
- `numeric_code`: Country Numeric code.
- `phonecode`: Country Phone code.
- `capital`: Capital of this country.
- `currency`: ISO-4177 Currency Code, e.g. USD, CNY.
- `currency_name`: Currency Name.
- `currency_symbol`: Currency Symbol e.g. $, ¥.
- `tld`: Country code top-level domain e.g. .uk.
- `native`: Local name of the country.
- `region`: region of the country.
- `subregion`: Sub-region of the country.
- `timezones`: timezones the country.
    - `zoneName`: Zone Name e.g. America/New\_York.
    - `gmtOffset`: GMT offset e.g. -18000.
    - `gmtOffsetName`: GMT offset Name e.g. UTC-05:00.
    - `abbreviation`: abbreviation e.g. EST.
    - `tzName`: time zone Name e.g. Eastern Standard Time (North America).
- `translations`: Country name translations e.g.
    - "ar": "الولايات المتحدة الأمريكية"
    - "kr": "미국"
    - "fr": "États-Unis"
- `latitude`: latitude the country.
- `longitude`: latitude the country.
- `emoji`: Emoji flag of country e.g. 🇺🇸.
- `emojiU`: Emoji Unicode flag of country e.g U+1F1FA U+1F1F8.
- `flag`: Country has flag (boolean).
- `is_active`: Country has active (boolean).

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

[](#installation)

You can install the package via composer:

```
composer require altwaireb/laravel-countries
```

Usage
-----

[](#usage)

Now run the following command to install .

```
php artisan countries:install
```

Add seeder File in `database\seeders\DatabaseSeeder.php` add this line to use `php artisan db:seed` command.

```
public function run(): void
    {

        $this->call(CountriesTableSeeder::class);
        ...
    }
```

Or you can Seed Data of Countries States Cities, by run this command.

```
php artisan countries:seeder
```

And you can refresh to re-seeding Data of Countries States Cities, by run this command.

```
php artisan countries:seeder --refresh
```

You can specify the activation of countries through the country code ISO2 or ISO3, before processing the seed data in the config file. `config/countries.php`

```
return [
    'insert_activations_only' => false,
    'countries' => [
        'activation' => [
            'default' => true,
            'only' => [
                'iso2' => ['SA','GB','DE'],
                'iso3' => ['USA','BRA','EGY'],
            ],
            'except' => [
                'iso2' => ['GA'],
                'iso3' => ['HTI'],
            ],
        ],
    ],

    'states' => [
        'activation' => [
            'default' => true,
        ],
    ],

    'cities' => [
        'activation' => [
            'default' => true,
        ],
    ],

    'chunk_length' => 50,
];
```

If you need to insert the countries is activation , this insert only two Countries `( Albania , Argentina )` with States and Cities.

```
return [
    'insert_activations_only' => true,
    'countries' => [
        'activation' => [
            'default' => true,
            'only' => [
                'iso2' => ['AL','AR'],
                'iso3' => [],
            ],
            'except' => [
                'iso2' => [],
                'iso3' => [],
            ],
        ],
    ],

    ...
];
```

This means that only these two countries and the states and cities affiliated with them will be activated.

- Note: If activation only `iso2` an `iso3` are empty, the column is\_active take the `default` value in config file.
- Note: If Country is active, all States and Cities are active.
- Note: If activation except `iso2` or `iso3` the column is\_active take FALSE value.
- Note: If Country is not active, all States and Cities are not active.

Usage
-----

[](#usage-1)

you can get country by iso2 and iso3 or both.

if you want to get country by iso2 you can yes static function getByIso2

```
use App\Models\Country;

$sa = Country::getByIso2('SA');
$sa->name; // Saudi Arabia
$sa->iso2; // SA
$sa->iso3; // SAU
$sa->currency_symbol; // ﷼
$sa->native; // المملكة العربية السعودية
```

if you want to get country by iso3 you can use.

```
use App\Models\Country;

$bra = Country::getByIso3('BRA');
$bra->name; // Brazil
$bra->iso2; // BR
$bra->iso3; // BRA
$bra->currency_symbol; // R$
$bra->native; // Brasil
```

also if you want to get country by code iso2 ro iso3 you can use.

```
use App\Models\Country;

$bra = Country::getByCode('PT');
$bra->name; // Portugal
$bra->iso2; // PT
$bra->iso3; // PRT
$bra->currency_symbol; // €
$bra->native; // Portugal
```

### Scope

[](#scope)

you can use Scope to filter data is Active by use.

```
use App\Models\Country;

$countries = Country::active()->pluck('name','id');
```

Credits
-------

[](#credits)

- [Abdulmajeed Altwaireb](https://github.com/altwaireb)
- [Alexandre Plennevaux](https://github.com/pixeline) (*Edit readme*)
- [All Contributors](../../contributors)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance64

Regular maintenance activity

Popularity31

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.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 ~0 days

Total

4

Last Release

353d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelLaravel-Countriesaltwaireb

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

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