larapkg/iso-countries

ISO 国家及其代码的地图

1.1.0 2022-02-12 19:11 UTC

This package is auto-updated.

Last update: 2024-09-13 02:28:40 UTC


README

IsoCountries

一个简单的PHP映射器,用于ISO国家数据。

国家数据在 data 文件夹中提供,以便于使用CSV、JSON和ODS格式。

使用方法

// Create an instance directly:
$countries = new \LaraPKG\IsoCountries\Countries();

// Could also be bound to a container:
//$this->app->singleton(Countries::class);
//$this->app->alias(Countries::class, 'countries');

国家记录以它们的两个字母ISO-3116-1 Alpha-2代码作为键。

$gb = $countries->get('GB');
$us = $countries->get('US');
$fr = $countries->get('FR');

国家类将调用转发到集合实例,因此可以使用任何Laravel Collection方法来检索国家记录。

$countries
    ->filter(static fn (Country $country) => $country->alpha3() === 'AUS')
    ->first();

可以将国家作为数组检索以在其他应用程序部分进行处理。

$countries->toArray();