Laravel package providing addressing functionality
galahad/laravel-addressing is a Laravel package for laravel package providing addressing functionality.
It currently has 69 GitHub stars and 332.099 downloads on Packagist (latest version 4.0.0).
Install it with composer require galahad/laravel-addressing.
Discover more Laravel packages by galahad
or browse all Laravel packages to compare alternatives.
Last updated
Laravel package providing addressing functionality based on
commerceguys/addressing
First, install the composer package:
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
You can use some custom validators in your Laravel app:
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
]);
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',
]);
You can use postal_code to validate the zip/postal code:
$this->validate($request, [
'postal_code' => 'required|postal_code:country_field,administrative_area_field',
]);
Laravel Addressing publishes two routes by default, which can be disabled in the config file.
The prefix (/galahad/addressing) can also be configured.
{
"label": "Countries",
"options": {
"AF": "Afghanistan",
"..": "...",
"ZW": "Zimbabwe"
}
}
{
"label": "States",
"country_code": "US",
"options": {
"AL": "Alabama",
"**": "*******",
"WY": "Wyoming"
}
}
This release adds Laravel 7 support and also is more permissive in its validators:
(The 2.0.0 release had a bug that failed to allow admin areas when we don't have data.)
This is the first stable release, with lots of breaking changes since 0.5.*
5.7 and the minimum supported PHP version is now 7.1.3Galahad\LaravelAddressing\ServiceProvider has been moved to Galahad\LaravelAddressing\Support\AddressingServiceProvider, so if you were manually registering the service provider, please update your app.php config file.Galahad\LaravelAddressing\Facades\Addressing has been moved to Galahad\LaravelAddressing\Support\Facades\Addressing, so if you were manually registering the service provider, please update your app.php config file.Galahad\LaravelAddressing\AddressFacade has been removedAddressFormatRepository, AdministrativeAreaRepository, CountryRepository) have been removed. Instead, countries are accessed via the facade or LaravelAddressing class, and everything else is loaded via its parent.CountryCollection and AdministrativeAreaCollection (getCountryCode(), etc) in favor of just calling getCountry() on the collection and then accessing the Country entity directly.LaravelAddressing::getCountryList() has been removed in favor of countries()->toSelectArray()Country::getAdministrativeAreasList() has been removed in favor of administrativeAreas()->toSelectArray()Entity\Country no longer extends CommerceGuys\Addressing\Country (which is now a final class), and instead provides a similar/decorated APIEntity\AdministrativeArea no longer extends CommerceGuys\Addressing\Subdivision\Subdivision, and instead extends Entity\Subdivision and provides a similar/decorated APIUS-PA) and instead by their country-specific codes (i.e. PA)Galahad\LaravelAddressing\Controller has been split up into separate controllers. If you're extending this, please see the Support/Http/ directory.$country->getPostalCodePattern() has been removed in favor of $country->addressFormat()->getPostalCodePattern()'country_input' => 'country_code'). If not, see src/Support/Validation/ for details./{country}/administrative-areas HTTP endpoint no longer returns an expected_length value and country has been renamed to country_codeaddressing.route.prefix has been renamed addressing.routes.prefix and addressing.routes.enabled has been addedUnknownCountryException is no longer thrown, and NULL is returned insteadSpecial thanks to Commerce Guys for their amazing addressing and intl packages, which this project relies heavily on.