Addresses
The Address module adds support for countries, provinces (state, county, region, etc), cities and addresses.
The Vanilo framework uses the
konekt/address library. If using
only some components of Vanilo, it's possible to use a different
implementation, the only requirement is to implement the
Vanilo\Contracts\Address
interface.
Please refer to the original address documentation for more details:
- Models:
- Enums:
- Seeders
Comparing Addresses
It is possible to compare addresses using the Addresses
utility class.
It can give a versatile comparison of two addresses and their differences.
$address1 = Address::create(['country_id' => 'US', 'city' => 'New York', 'address' => '1234th Street 66']);
$address2 = Address::create(['country_id' => 'US', 'city' => 'New York', 'address' => '1234th Street 67']);
Addresses::are($address1, $address2)->inTheSameCountry();
// true
Addresses::are($address1, $address2)->inTheSameCity();
// true
Addresses::are($address1, $address2)->atDifferentAddresses();
// true
Addresses::are($address1, $address2)->identical();
// false
Addresses::are($address1, $address2)->different();
// true
The utility makes distinction between cities of the same name in different countries
$berlinUS = Address::create(['country_id' => 'DE', 'city' => 'Berlin']);
$berlinDE = Address::create(['country_id' => 'US', 'city' => 'Berlin']);
Addresses::are($berlinUS, $berlinDE)->inDifferentCountries();
// true
Addresses::are($berlinUS, $berlinDE)->inDifferentCities();
// true
Addresses::are($berlinUS, $berlinDE)->atDifferentAddresses();
// true
It even can compare two cities of the same name in the same country, but in different provinces:
$berlinGeorgia = Address::create(['country_id' => 'US', 'city' => 'Berlin', 'province_id' => 'GA']);
$berlinAlabama = Address::create(['country_id' => 'US', 'city' => 'Berlin', 'province_id' => 'AL']);
Addresses::are($berlinUS, $berlinDE)->inTheSameCountry();
// true
Addresses::are($berlinUS, $berlinDE)->inDifferentCities();
// true
Addresses::are($berlinUS, $berlinDE)->inDifferentProvinces();
// true