bkfdev/laravel-world

:package_description

v3.0.5 2024-06-05 08:08 UTC

This package is auto-updated.

Last update: 2024-09-05 08:37:08 UTC


README

Latest Version on Packagist Total Downloads Build Status StyleCI

Laravel-World 是一个 Laravel 扩展包,提供国家、州、城市、时区、货币和语言的列表。

可以使用 World Facade 进行消费

安装

通过 Composer

    composer require bkfdev/laravel-world

发布

    php artisan vendor:publish --force --provider="Bkfdev\World\LaravelWorldServiceProvider"

设置配置

<?php

return [
    /*
	|--------------------------------------------------------------------------
	| Allowed countries to be loaded
	| Leave it empty to load all countries
	|--------------------------------------------------------------------------
	*/
    'allowed_countries' => [],

    /*
	|--------------------------------------------------------------------------
	| Disallowed countries to not be loaded
	| Leave it empty to allow all countries to be loaded
	|--------------------------------------------------------------------------
	*/
    'disallowed_countries' => [],

    /*
	|--------------------------------------------------------------------------
	| Supported locales.
	|--------------------------------------------------------------------------
	*/
    'accepted_locales' => [
        'ar',
        'en',
        /* 'bn',
        'br',
        'de',
        'es',
        'fr',
        'ja',
        'kr',
        'nl',
        'pl',
        'pt',
        'ro',
        'ru',
        'zh', */
    ],
    /*
	|--------------------------------------------------------------------------
	| Enabled modules.
	| The cities module depends on the states module.
	|--------------------------------------------------------------------------
	*/
    'modules' => [
        'states' => true,
        'cities' => true,
        'timezones' => true,
        'currencies' => true,
        'languages' => true,
    ],

    /*
	|--------------------------------------------------------------------------
	| Migrations.
	|--------------------------------------------------------------------------
	*/
    'migrations' => [
        'countries' => [
            'table_name' => 'world_countries',
            'optional_fields' => [

    ...

迁移

    php artisan migrate

运行命令以导入数据

    php artisan world:init

或者您可以通过运行此命令添加一些国家

    php artisan world:add us sa dz

使用方法

它只是一个 eloquent,所以您可以运行任何想要的命令

    use Bkfdev\World\World;
获取所有国家
    $countries = World::Countries();
通过代码 iso2 或 iso3 获取国家
    $country = World::getCountryByCode($code);
    return :
    [
        "id" => 1
        "iso2" => "DZ"
        "name" => "Algeria"
        "status" => 1
        "phone_code" => "213"
        "iso3" => "DZA"
        "native" => "الجزائر"
        "region" => "Africa"
        "subregion" => "Northern Africa"
        "latitude" => "28.00000000"
        "longitude" => "3.00000000"
        "emoji" => "🇩🇿"
        "emojiU" => "U+1F1E9 U+1F1FF"
    ]
通过名称获取国家
    $country = World::getCountryByName($name);
通过代码获取给定国家的州
    $states = World::getStatesOfCountry($code);

变更日志

请参阅 changelog 获取最近更改的更多信息。

测试

    composer test

贡献

请参阅 contributing.md 获取详细信息和一个待办事项列表。

安全

如果您发现任何与安全相关的问题,请通过电子邮件 bkfdev@gmail.com 而不是使用问题跟踪器。

鸣谢

许可

MIT。请参阅 许可文件 获取更多信息。