arkadedigital/country-list

Laravel 和 Lumen 的所有国家名称和 ISO 3166-1 代码的完整列表。

这个包的官方仓库似乎已不存在,因此该包已被冻结。

v1.0.0 2016-09-13 11:26 UTC

This package is not auto-updated.

Last update: 2024-07-20 18:36:42 UTC


README

国家列表

国家列表是一个 Laravel 和 Lumen 的包,列出了所有国家及其名称和 ISO 3166-1 代码,支持所有语言和数据格式。

安装

使用 Composerarkadedigital/country-list 添加到您的 Laravel 或 Lumen 项目中。

composer require arkadedigital/country-list

Laravel

打开 app/config/app.php 并将服务提供者添加到 providers 数组中。

'providers' => [
    Arkadedigital\CountryList\CountryListServiceProvider::class,
]

最后,添加别名。

'aliases' => [
    'Countries' => Arkadedigital\CountryList\CountryListFacade::class,
]

Lumen

打开 bootstrap/app.php 并将服务提供者添加到文件中。

$app->register(Arkadedigital\CountryList\CountryListServiceProvider::class);

用法

  • 区域设置(en, en_US, fr, fr_CA...)
  • 格式(csv, html, json, mysql.sql, php, postgresql.sql, sqlite.sql, txt, xliff, xml, yaml)

获取所有国家的英文 JSON 数据

Route::get('/', function() {
    return Countries::getList('en', 'json');
});

获取俄国的英文名称

Route::get('/', function() {
    return Countries::getOne('RU', 'en');
});

依赖注入

如果您使用 Lumen 或更喜欢 Laravel 的外观,则可以选择使用依赖注入。

use Arkadedigital\CountryList\CountryList;

class Controller extends BaseController
{
    protected $countryList;

    public function __construct(CountryList $countryList)
    {
        $this->countryList = $countryList;
    }

    public function index()
    {
        return $this->countryList->getList('en', 'csv');
    }
}

支持

请随时 创建 GitHub 问题给我们发送邮件 以获得有关此 Laravel 包的支持。

致谢

此项目是 Monarobase 的 Country List 项目的分支。