galahad / laravel-addressing
Laravel 提供地址功能的包
3.3.0
2024-07-22 17:10 UTC
Requires
- php: >=7.4
- commerceguys/addressing: ^v1.2
- commerceguys/intl: ^v1.1
- doctrine/collections: ^1.6.2
- illuminate/contracts: ^v7|^8|^9|^10|^11|12.x-dev|dev-master
- illuminate/http: ^v7|^8|^9|^10|^11|12.x-dev|dev-master
- illuminate/routing: ^v7|^8|^9|^10|^11|12.x-dev|dev-master
- illuminate/support: ^v7|^8|^9|^10|^11|12.x-dev|dev-master
- illuminate/validation: ^v7|^8|^9|^10|^11|12.x-dev|dev-master
- symfony/intl: ^v4.2|^v5.0|^v6.0|^7.0
Requires (Dev)
- ext-json: *
- friendsofphp/php-cs-fixer: ^3.0
- orchestra/testbench: ^5.20|^6.24|^7.10|^8|9.x-dev|10.x-dev|dev-master
- phpunit/phpunit: ^9.5|^10
- dev-master
- dev-main
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.0
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.1
- 2.0.0
- 1.0.x-dev
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0-beta
- v0.5.x-dev
- 0.5.1
- 0.5.0
- 0.5.0-beta2
- 0.5.0-beta1
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
- dev-remove-routes-file
- dev-development
- dev-postal-validation-fix
This package is auto-updated.
Last update: 2024-09-22 17:26:14 UTC
README
Laravel Addressing
Laravel Addressing 是一个基于 commerceguys/addressing 的 Laravel 包,提供地址功能。它允许您使用 CLDR 和 Google 的数据轻松处理地址。
Laravel Addressing 的主要重点是
- 访问最新版的国列表、州/省等
- 轻松验证地址数据
- 格式化地址以符合特定国家的规则
如果您觉得这个包很有用,您应该检查我们的通用地址输入 Franklin,它与 Laravel Addressing 遵循相同的约定。
安装
首先,安装 composer 包
composer require galahad/laravel-addressing
基本用法
国家
$country = Addressing::country('US'); echo $country->getName(); // "United States" echo $country->getCountryCode(); // "US"
行政区域(通常是州或省)
$usa = Addressing::country('US'); echo $usa->administrativeArea('AL')->getName(); // "Alabama" echo $usa->administrativeArea('AL')->getCode(); // "AL" typeof $usa->administrativeAreas() // AdministrativeAreaCollection
验证器
您可以在您的 Laravel 应用程序中使用一些自定义验证器
国家
您可以使用 country、country_code 或 country_name 验证国家输入
$this->validate($request, [ 'country' => 'required|country_code', // Must be a 2-letter ISO code, such as "US" ]); $this->validate($request, [ 'country' => 'required|country_name', // Must be the full country name, such as "United States" ]); $this->validate($request, [ 'country' => 'required|country', // Must be the full country name or 2-letter ISO code ]);
行政区域
您可以使用 administrative_area、administrative_area_code 或 administrative_area_name 验证行政区域输入
// "country_field" is the form input that represents the country to validate against $this->validate($request, [ 'state' => 'required|administrative_area_code:name_of_country_field', ]); $this->validate($request, [ 'state' => 'required|administrative_area_name:country_field', ]); $this->validate($request, [ 'state' => 'required|administrative_area:country_field', ]);
邮政编码
您可以使用 postal_code 验证邮政编码
$this->validate($request, [ 'postal_code' => 'required|postal_code:country_field,administrative_area_field', ]);
HTTP 端点
Laravel Addressing 默认发布两个路由,这些路由可以在配置文件中禁用。前缀 (/galahad/addressing) 也可以配置。
GET /galahad/addressing/countries
{
"label": "Countries",
"options": {
"AF": "Afghanistan",
"..": "...",
"ZW": "Zimbabwe"
}
}
GET /galahad/addressing/countries/us/administrative-areas
{
"label": "States",
"country_code": "US",
"options": {
"AL": "Alabama",
"**": "*******",
"WY": "Wyoming"
}
}
谢谢!
特别感谢 Commerce Guys 及其出色的 addressing 和 intl 包,本项目严重依赖于这些包。