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.
Requires
- php: ^8.2|^8.3
- astrotomic/laravel-translatable: ^11.17
- laravel/framework: ^10.48|^11.31|^12.0|^13.0
- spatie/laravel-package-tools: ^1.93
Requires (Dev)
- doctrine/dbal: ^3.0
- laravel/legacy-factories: ^1.4
- laravel/pint: ^1.29
- mockery/mockery: ^1.6
- orchestra/testbench: ^9.12|^10.0|^11.0
- pestphp/pest: ^3.7|^4.4
- pestphp/pest-plugin-laravel: ^3.1|^4.1
README
Laravel Countries
The Eloquent-first country database for Laravel โ every ISO code, flag, GeoJSON border and translation, one Country:: call away.
๐ 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.
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_idforeign key tousers,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
- Lucas Duarte
- Saad Batwa โ detailed review and corrections of Arabic country translations (PR #45)
- ฤฐlyas รzkurt โ Turkish language translations (PR #36)
- All Contributors
๐ License
The MIT License (MIT). Please see LICENSE.md for more information.
Made with โค๏ธ for the Laravel community
