Download the PHP package divineomega/laravel-addresses without Composer
On this page you can find all versions of the php package divineomega/laravel-addresses. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download divineomega/laravel-addresses
More information about divineomega/laravel-addresses
Files in divineomega/laravel-addresses
Package laravel-addresses
Short Description Laravel Addresses
License LGPL-3.0-only
Informations about the package laravel-addresses
Laravel Addresses
Laravel Addresses is a package that lets you associate addresses with your Laravel Eloquent models.
Features:
- Automatic geocoding of addresses on change, provided by the Google Maps API
- Validation of address details (country, postcode)
- Conversion of ISO country code to country name
- Ability to store meta data about addresses - e.g.
['type' => 'delivery', 'name' => 'home_address']
Installation
To install Laravel Addresses, just run the following Composer command.
Configuration
Run the following Artisan command to publish the configuration file.
This will create the default configuration file at config/addresses.php
.
Note that by default, you require a Google Maps API key in order to provide address geocoding and distance calculations. If you do not wish to use geocoding, this can be disabled in the configuration.
Strict geocoding
By default, geocoding is configured as "lenient"; if, for example, the name of a real city is given but the postcode and street address refer to a nonexistent place, it will geocode as the center of that city.
Set the geocoding.strict
flag to true
in the configuration file to instead fail to geocode in
this scenario.
Usage
Assign the HasAddresses
trait to the model you wish to have associated addresses.
For example, you could give the default User
model address, as shown below.
Retrieve addresses
Create new address
Geocoding
Geocoding is automatic when an address is created or updated. You can check if
an address was successfully geocoding using the isGeocoded
method.
You can also manually geocode the address if needed.
Note that geocoding can fail, in which case, you can detect that it failed by checking whether the address is geocoded after attempting geocoding:
If there was an existing latitude/longitude set and geocoding fails, these are cleared.
Validation
Validation is automatic when an address is created or updated. You can expect an appropriate exception to be thrown if validation fails.
InvalidCountryException
- Providedcountry_code
is not a valid ISO 3166-1 alpha-3 country code.InvalidUKPostcodeException
- If the address is within the UK, the providedpostcode
is not a valid UK postcode.
You can also manually validate the address if needed.
Distance calculation
The distance between two different addresses can be calculated using the distanceTo
method.
By default the direct distance is calculated (as the crow flies). If you want, you can specify a different type of distance calculation, such as driving distance.
All versions of laravel-addresses with dependencies
laravel/framework Version ^5.6||^6.0||^7.0||^8.0||^9.0
divineomega/php-countries Version ^2.1
divineomega/php-postcodes Version ^4.5
langleyfoxall/simple-google-maps Version ^1.0
divineomega/php-distance Version ^1.0