danielebuso/laravel-countries
Composer 安装命令:
composer require danielebuso/laravel-countries
包简介
A Laravel package providing country data with multilanguage support using Sushi
README 文档
README
A Laravel package that provides an easy way to query and browse country data with multilanguage support using Sushi. Unlike other country packages, this one includes country names in multiple languages, making it perfect for international applications.
This package uses data structure inspired by stefangabos/world_countries and leverages Sushi to provide a seamless Eloquent-like interface for static country data.
Features
- 🌍 Complete ISO 3166-1 list with 249 entities including countries, territories, and dependencies
- 🌐 Multilanguage support - Country names in multiple languages (English, Spanish, French, Italian, German, Croatian, and more)
- 🔍 Query countries using Laravel's Eloquent ORM
- ⚡ Fast performance with Sushi's in-memory caching
- 🎯 Simple and intuitive API
- 📦 Zero database migrations required
Installation
You can install the package via composer:
composer require danielebuso/laravel-countries
You can publish the config file with:
php artisan vendor:publish --tag="laravel-countries-config"
This is the contents of the published config file:
return [ /* * The default locale to use when retrieving country names. * If not set, it will use Laravel's app locale. */ 'locale' => null, /* * Cache configuration for country data. * Sushi automatically caches the data, but you can configure it here. */ 'cache' => [ 'enabled' => true, 'ttl' => 3600, // Time in seconds ], ];
Usage
What's Included
This package includes the complete ISO 3166-1 standard with 249 entities:
- Sovereign states: All 193 UN member states plus Vatican City, Palestine, Kosovo, Taiwan
- Territories: Puerto Rico, Guam, U.S. Virgin Islands, American Samoa, etc.
- Dependencies: Greenland, Bermuda, French Polynesia, Faroe Islands, etc.
- Special Administrative Regions: Hong Kong, Macau
- Other entities: Antarctica, Åland Islands, and more
This comprehensive list ensures you have access to all officially recognized ISO codes, not just UN member states.
Basic Usage
use Danielebuso\LaravelCountries\Models\Country; // Get all countries $countries = Country::all(); // Find a country by alpha-2 code $usa = Country::where('alpha2', 'US')->first(); // Find a country by alpha-3 code $italy = Country::where('alpha3', 'ITA')->first(); // Get countries sorted by name $countries = Country::orderBy('name')->get();
Multilanguage Support
The package includes built-in support for multiple languages. Country names are available in:
- English (en) - Default
- Spanish (es)
- French (fr)
- Italian (it)
- German (de)
- Croatian (hr)
use Danielebuso\LaravelCountries\Models\Country; // Get country name in a specific language $italy = Country::where('alpha2', 'IT')->first(); // Get name in Italian $italianName = $italy->getName('it'); // Returns "Italia" // Get name in Spanish $spanishName = $italy->getName('es'); // Returns "Italia" // Get name in French $frenchName = $italy->getName('fr'); // Returns "Italie" // Get name in Croatian $croatianName = $italy->getName('hr'); // Returns "Italija" // Get name using app's current locale app()->setLocale('es'); $localizedName = $italy->getName(); // Returns "Italia" (Spanish)
Query Examples
// Search countries by name $countries = Country::where('name', 'LIKE', '%United%')->get(); // Get a specific country $germany = Country::where('alpha2', 'DE')->first(); echo $germany->name; // Germany echo $germany->alpha3; // DEU echo $germany->id; // 276 // Count all countries $total = Country::count(); // Pagination $countries = Country::paginate(20);
Available Fields
Each country model has the following attributes:
id- ISO 3166-1 numeric codealpha2- ISO 3166-1 alpha-2 code (e.g., 'US', 'IT', 'FR')alpha3- ISO 3166-1 alpha-3 code (e.g., 'USA', 'ITA', 'FRA')name- Country name in English
Why This Package?
While there are several Laravel packages that provide country data, this package stands out because:
- Multilanguage Support: Unlike most packages, this one includes country names in multiple languages out of the box
- No Database Required: Uses Sushi to work with static data without migrations
- Familiar API: Works just like any Eloquent model
- Actively Maintained: Built on modern Laravel standards
- Lightweight: Minimal dependencies and fast performance
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Daniele Buso
- All Contributors
- Data structure inspired by stefangabos/world_countries
License
The MIT License (MIT). Please see License File for more information.
danielebuso/laravel-countries 适用场景与选型建议
danielebuso/laravel-countries 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 265 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「multilanguage」 「laravel」 「countries」 「Laravel-Countries」 「danielebuso」 「sushi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 danielebuso/laravel-countries 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 danielebuso/laravel-countries 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 danielebuso/laravel-countries 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Puts the Symfony Translation Component on steroids
List of all countries with names and ISO 3166-1 codes in all languages and data formats for Laravel
Laravel 5.2 package that provides basic geographical data like Countries, Regions and Cities.
Puts the Symfony Translation Component on steroids
A package to delivery a wide seed array of Countries & their respective cities.
统计信息
- 总下载量: 265
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-04