galahad / laravel-addressing
Laravel package providing addressing functionality
Installs: 240 523
Dependents: 0
Suggesters: 0
Security: 0
Stars: 63
Watchers: 5
Forks: 14
Open Issues: 0
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-11-22 17:54:14 UTC
README
Laravel Addressing
Laravel Addressing is a Laravel package providing addressing functionality based on
commerceguys/addressing
. It lets you easily
work with addresses using data from CLDR and Google.
The primary focus of Laravel Addressing is:
- Access to up-to-date lists of countries, states/provinces, etc
- Easily validate address data
- Format addresses to match a specific country's rules
If you find this package useful, you should check out Franklin, our universal address input that follows the same conventions as Laravel Addressing.
Installation
First, install the composer package:
composer require galahad/laravel-addressing
Basic Usage
Country
$country = Addressing::country('US'); echo $country->getName(); // "United States" echo $country->getCountryCode(); // "US"
Administrative Area (typically states or provinces)
$usa = Addressing::country('US'); echo $usa->administrativeArea('AL')->getName(); // "Alabama" echo $usa->administrativeArea('AL')->getCode(); // "AL" typeof $usa->administrativeAreas() // AdministrativeAreaCollection
Validators
You can use some custom validators in your Laravel app:
Countries
You can use country
, country_code
, or country_name
to validate country input:
$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 Areas
You can use administrative_area
, administrative_area_code
, or administrative_area_name
to validate administrative area input:
// "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
You can use postal_code
to validate the zip/postal code:
$this->validate($request, [ 'postal_code' => 'required|postal_code:country_field,administrative_area_field', ]);
HTTP Endpoints
Laravel Addressing publishes two routes by default, which can be disabled in the config file.
The prefix (/galahad/addressing
) can also be configured.
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" } }
Thanks!
Special thanks to Commerce Guys for their amazing addressing and intl packages, which this project relies heavily on.