bardolf69/laravel11-countries-states-cities
Composer 安装命令:
composer require bardolf69/laravel11-countries-states-cities
包简介
Laravel Countries States Cities DB Migration & Seeder
关键字:
README 文档
README
Countries States Cities Data for Laravel
Numbers
| Model | Number of items |
|---|---|
| Country | 250 |
| State | 4961 |
| City | 148059 |
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
You can install the package via composer:
composer require bardolf69/laravel-countries-states-cities
Usage
Now run the following command to install .
php artisan countries-states-cities: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(CountriesStatesCitiesTableSeeder::class); ... }
Or you can Seeding Data of Countries States Cities, by run this command.
php artisan countries-states-cities:seeder
And you can refresh to re-seeding Data of Countries States Cities, by run this command.
php artisan countries-states-cities: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-states-cities.php
return [ 'countries' => [ 'activation' => [ 'default' => true, 'only' => [ 'iso2' => ['SA','GB','DE'], 'iso3' => ['USA','BRA','EGY'], ], 'except' => [ 'iso2' => ['GA'], 'iso3' => ['HTI'], ], ], 'chunk_length' => 50, ], 'states' => [ 'activation' => [ 'default' => true, ], 'chunk_length' => 200, ], 'cities' => [ 'activation' => [ 'default' => true, ], 'chunk_length' => 200, ], ];
This means that only these two countries and the states and cities affiliated with them will be activated.
- Note: If activation only
iso2aniso3are empty, the column is_active take thedefaultvalue in config file. - Note: If Country is active, all States and Cities are active.
- Note: If activation except
iso2oriso3the column is_active take FALSE value. - Note: If Country is not active, all States and Cities are not active.
Usage
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
you can use Scope to filter data is Active by use.
use App\Models\Country; $countries = Country::active()->pluck('name','id');
Credits
License
The MIT License (MIT). Please see License File for more information.
bardolf69/laravel11-countries-states-cities 适用场景与选型建议
bardolf69/laravel11-countries-states-cities 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 72 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「states」 「countries」 「cities」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bardolf69/laravel11-countries-states-cities 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bardolf69/laravel11-countries-states-cities 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bardolf69/laravel11-countries-states-cities 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
List of all countries with names and ISO 3166-1 codes in all languages and data formats for Laravel
PHP extension with Brazilian states and formats for CPF, CNPJ and ZIP
Laravel 5.2 package that provides basic geographical data like Countries, Regions and Cities.
A simple PHP class for United States Postal Service (USPS) addresses
Convert and operate with FIPS codes for states, counties, etc.
PHP Countries and Currencies
统计信息
- 总下载量: 72
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-14