PHPackages                             jord-jd/laravel-addresses - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jord-jd/laravel-addresses

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jord-jd/laravel-addresses
=========================

Laravel Addresses

v2.1.0(1mo ago)803LGPL-3.0-onlyPHPPHP &gt;=7.1CI passing

Since Feb 1Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/Jord-JD/laravel-addresses)[ Packagist](https://packagist.org/packages/jord-jd/laravel-addresses)[ GitHub Sponsors](https://github.com/DivineOmega)[ RSS](/packages/jord-jd-laravel-addresses/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (12)Versions (19)Used By (0)

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']`

Compatibility
-------------

[](#compatibility)

This package supports Laravel versions 5.6 through 13.

Installation
------------

[](#installation)

To install Laravel Addresses, just run the following Composer command.

```
composer require jord-jd/laravel-addresses
```

Configuration
-------------

[](#configuration)

Run the following Artisan command to publish the configuration file.

```
php artisan vendor:publish --provider="JordJD\LaravelAddresses\ServiceProvider" --force
```

This will create the default configuration file at `config/addresses.php`.

### Custom address model

[](#custom-address-model)

To add relationships, accessors, or other application-specific behaviour to addresses, extend the package model and set the `model` configuration value to your class:

```
namespace App\Models;

class Address extends \JordJD\LaravelAddresses\Models\Address
{
    // Your custom behaviour.
}
```

```
// config/addresses.php
'model' => App\Models\Address::class,
```

The relationship traits and model observer will both use the configured class. Custom models must extend `JordJD\LaravelAddresses\Models\Address`.

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

[](#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
-----

[](#usage)

Assign the `HasAddresses` trait to a model that can have multiple associated addresses. For example, you could give the default `User` model addresses, as shown below.

```
