定制 altwaireb/laravel-world 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

altwaireb/laravel-world

Composer 安装命令:

composer require altwaireb/laravel-world

包简介

Laravel World, Countries States Cities DB Migration & Seeder

README 文档

README

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

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.
  • iso3: 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 altwaireb/laravel-world

Usage

Now run the following command to install:

php artisan world:install

Add the seeder file in database\seeders\DatabaseSeeder.php and add this line to use the php artisan db:seed command.

public function run(): void
    {

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

Alternatively, you can seed data for Countries, States, and Cities by running this command.

php artisan world:seeder

You can also refresh to re-seed data for Countries, States, and Cities by running this command.

php artisan world: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/world.php.

return [
    'insert_activations_only' => false,
    '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,
    ],
];

If you need to insert only the activated countries, this will insert only two countries (Albania and Argentina) with their States and Cities.

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

    ...
];

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

  • Note: If both iso2 and iso3 are empty, the is_active column takes the default value from the config file.
  • Note: If a country is active, all its states and cities are active.
  • Note: If a country is in the except list for iso2 or iso3, the is_active column takes the FALSE value.
  • Note: If a country is not active, all its states and cities are not active.

Usage

You can get a country by its ISO2 or ISO3 code, or both. If you want to get a country by ISO2, you can use the 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 a country by ISO3, you can use the following.

use App\Models\Country;

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

And if you want to get a country by either ISO2 or ISO3 code, you can use the following.

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 active data by using the following.

use App\Models\Country;

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

Credits

License

The MIT License (MIT). Please see License File for more information.

altwaireb/laravel-world 适用场景与选型建议

altwaireb/laravel-world 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.79k 次下载、GitHub Stars 达 99, 最近一次更新时间为 2024 年 06 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「states」 「countries」 「cities」 「Laravel-World」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 altwaireb/laravel-world 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 altwaireb/laravel-world 我们能提供哪些服务?
定制开发 / 二次开发

基于 altwaireb/laravel-world 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11.79k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 100
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 99
  • Watchers: 4
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-24