lwwcas/laravel-countries

A comprehensive package for managing country data in Laravel applications, including multilingual support, geographic coordinates, and detailed metadata for seamless integration with Laravel.

Maintainers

Package info

github.com/lwwcas/laravel-countries

Homepage

Documentation

pkg:composer/lwwcas/laravel-countries

Transparency log

Statistics

Installs: 77 126

Dependents: 0

Suggesters: 0

Stars: 127

Open Issues: 3

4.13.5 2026-07-16 09:03 UTC

README

Laravel Countries โ€” Eloquent country database package for Laravel with ISO codes, flags, GeoJSON and translations

Laravel Countries

The Eloquent-first country database for Laravel โ€” every ISO code, flag, GeoJSON border and translation, one Country:: call away.

Latest release Tests PHP version Total downloads Stars Contributors Last commit License

๐Ÿ“š Full documentation โ€” this README is just the quick-start version

Laravel Countries is an Eloquent-first package that models the entire world as native Laravel relationships: ISO 3166 codes (Alpha-2, Alpha-3, numeric), international phone codes, currencies, national flags (SVG, emoji, HEX/RGB colors), GeoJSON borders, geographic coordinates, demographics, GDP, independence dates and region hierarchies โ€” all translated into 9 languages and seeded straight into your own database.

No external APIs. No JSON files to fetch, parse and cache yourself. No stale array copy-pasted from a gist. Install the package, run one Artisan command, and countries behave like any other Eloquent model in your app โ€” queryable, relatable, cacheable, testable.

โญ Enjoying this package?

If Laravel Countries saved you some time, consider leaving a star on the repo. It's free, takes two seconds, and it's the main way other developers find this project.

๐Ÿ‘‰ Star Laravel Countries on GitHub

On this page

Why Laravel Countries? โ€ข Features โ€ข Data Model โ€ข Available Languages โ€ข Getting Started โ€ข Usage โ€ข Testing โ€ข Contributing

๐Ÿค” Why Laravel Countries?

Most "country list" packages for PHP give you a static array or a JSON file with a name and a two-letter code โ€” fine for a dropdown, useless for anything real.

Laravel Countries is built for applications that actually do something with country data:

  • It's a real Eloquent model, not a helper function. Country::whereIso('BR')->first() behaves like any other model โ€” relationships, scopes, eager loading, caching, all included.
  • It lives in your database, not in a vendor JSON file. Link a country_id foreign key to users, addresses, orders โ€” whatever your app needs โ€” with a normal Eloquent relationship.
  • It's translated, not just in English. Country and region names ship pre-translated in 9 languages, reviewed by native-speaking contributors โ€” not machine-translated on the fly.
  • It's geographic, not just alphabetical. GeoJSON borders and coordinates mean you can actually draw a map, not just print a list.
  • It's tested. CI-checked against Laravel 11, 12 and 13 with a full Pest suite โ€” not a "works on my machine" side project.
  • It only takes up the space you actually need. Install just the languages your app uses โ€” add or drop languages later without touching the rest of your data, so your database never carries translations you'll never query.

โœจ Features

  • ๐Ÿ—„๏ธ Eloquent-native country model โ€” Country:: behaves like any other Laravel model: scopes, relationships, eager loading
  • ๐ŸŒ ISO 3166 codes โ€” Alpha-2, Alpha-3 and numeric, all queryable (whereIso, whereIsoAlpha3, whereIsoNumeric)
  • โ˜Ž๏ธ International phone codes โ€” validate and query by dialing code (wherePhoneCode)
  • ๐Ÿ’ฑ Currency data โ€” query countries by currency
  • ๐Ÿณ๏ธ Flags in 3 formats โ€” SVG, emoji, and flag colors in HEX/RGB
  • ๐Ÿ—บ๏ธ GeoJSON borders + coordinates โ€” precise geographic data, ready for maps
  • ๐Ÿ“Š Demographics & economics โ€” population, area (kmยฒ), GDP
  • ๐Ÿ•Š๏ธ Independence dates & bordering countries
  • ๐ŸŒ Region hierarchy โ€” continents and regions, translated too
  • ๐Ÿ—ฃ๏ธ 9 languages built-in โ€” no separate i18n package needed (see table below)
  • ๐Ÿงฉ Install only the languages you need โ€” pick them at install time, then add or remove languages whenever you want, keeping your database lean instead of seeding all 9 by default
  • โšก One Artisan command to install and seed everything, idempotent and CI-safe
  • โœ… Tested with Pest, CI-checked against Laravel 11, 12, and 13
  • ๐Ÿšซ Zero external API calls โ€” everything is seeded once, queried locally, forever

๐Ÿ—บ๏ธ Data Model

A quick look at what's on the Country model (full reference in the Method Listing docs):

Category Fields / capabilities
Identity ISO Alpha-2, ISO Alpha-3, ISO numeric, slug, UID, official name
Geography Latitude/longitude, GeoJSON borders, area (kmยฒ), bordering countries
Economy Currency, GDP
Demography Population
Communication International phone code, top-level domain (TLD)
Identity/branding Flag (SVG), flag emoji, flag colors (HEX/RGB)
History Independence date
Classification Region / continent, WMO code
Localization Name and region translated in 9 languages

๐ŸŒ Available Languages

Every country and region name is translated in all 9 languages below โ€” the table shows how many countries have that language as an official/native language, not translation coverage (translation coverage is 100% across all languages).

You don't have to install all 9. Pick only the languages your app actually serves at install time, and add or remove languages later โ€” Laravel Countries manages the translation rows for you, so your database only ever stores what you're using.

Language Flag Country Countries where it's an official language
Arabic ๐Ÿ‡ธ๐Ÿ‡ฆ Saudi Arabia 25
Dutch ๐Ÿ‡ณ๐Ÿ‡ฑ Netherlands 3
English ๐Ÿ‡ฌ๐Ÿ‡ง United Kingdom 67
German ๐Ÿ‡ฉ๐Ÿ‡ช Germany 6
Italian ๐Ÿ‡ฎ๐Ÿ‡น Italy 4
Portuguese ๐Ÿ‡ง๐Ÿ‡ท Brazil 9
Russian ๐Ÿ‡ท๐Ÿ‡บ Russia 4
Spanish ๐Ÿ‡ช๐Ÿ‡ธ Spain 21
Turkish ๐Ÿ‡น๐Ÿ‡ท Turkey 2

Missing a language? Contributions are welcome โ€” the guide explains how translations get reviewed.

๐Ÿš€ Getting Started

Install via Composer:

composer require lwwcas/laravel-countries

Run the installer:

php artisan w-countries:install

That's it โ€” the countries table is seeded and ready to query.

Production / CI (Laravel 11, 12, and 13)

In production, use --force to skip confirmation prompts:

php artisan w-countries:install --force

If migrations already ran during deploy and you only need the data:

php artisan w-countries:seed --languages=en,pt,es

To list the equivalent manual db:seed commands:

php artisan w-countries:seed --show-commands

See the Seeders documentation for the full production guide and manual seeder class reference.

๐Ÿงฉ Manage languages anytime

Only need Portuguese and English today? Only seed those two โ€” there's no need to carry all 9 languages in your database if your app doesn't use them:

php artisan w-countries:seed --languages=en,pt

Adding a new market later (say, Spanish) doesn't mean starting over โ€” install the new language on top of what you already have. The same applies in reverse: if a language is no longer needed, you can remove it without touching the rest of your country data.

Full add/remove workflow and command reference โ†’ Available Languages docs

๐Ÿง‘โ€๐Ÿ’ป Usage & Query Examples

Basic lookups:

use Lwwcas\LaravelCountries\Models\Country;

Country::whereIso('BR')->first();
Country::whereIsoAlpha3('BRA')->first();
Country::whereSlug('brasil')->first();

Flags โ€” SVG, emoji, and colors:

$country = Country::whereIso('FR')->first();

$country->flag_svg;    // SVG markup
$country->flag_emoji;  // ๐Ÿ‡ซ๐Ÿ‡ท
$country->flag_colors; // ['#0055A4', '#FFFFFF', '#EF4135']

Phone codes & currency:

Country::wherePhoneCode('+55')->first();
Country::whereGdp(1000)->get(); // GDP in billions USD

Geographic data โ€” coordinates & GeoJSON:

$country = Country::whereIso('JP')->first();

$country->latitude;
$country->longitude;
$country->geojson; // ready to drop into any map library

Language & region:

Country::whereLanguage('en')->get();
Country::whereLanguages(['en', 'fr'])->get();

Looking for relationships, scopes, config, or translation helpers? โ†’ See the full documentation

๐Ÿงช Testing

composer test

๐Ÿค Contributing

Contributions, translations, and bug reports are very welcome. Please read CONTRIBUTING.md before opening a pull request.

๐Ÿ‘ฅ Credits

๐Ÿ“„ License

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

Made with โค๏ธ for the Laravel community