PHPackages                             alperenelbasan/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. alperenelbasan/laravel-addresses

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

alperenelbasan/laravel-addresses
================================

Simple address and contact management for Laravel.

v1.0.0(1y ago)05MITPHPPHP ^8.1

Since Sep 18Pushed 1y agoCompare

[ Source](https://github.com/AlperenElbasan/Laravel-Addresses)[ Packagist](https://packagist.org/packages/alperenelbasan/laravel-addresses)[ Docs](https://github.com/Lecturize/Laravel-Addresses)[ RSS](/packages/alperenelbasan-laravel-addresses/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/0142706a63a8b5658edf9afa0689b50b7d9e7ef625c0a821bd9659dbf75cf60b/68747470733a2f2f706f7365722e707567782e6f72672f6c6563747572697a652f6c61726176656c2d6164647265737365732f762f737461626c65)](https://packagist.org/packages/lecturize/laravel-addresses)[![Total Downloads](https://camo.githubusercontent.com/28ecc73a1d66921606adb047f16cd9e4ca9fa3f1c621b3d680b31d973b4a7a8d/68747470733a2f2f706f7365722e707567782e6f72672f6c6563747572697a652f6c61726176656c2d6164647265737365732f646f776e6c6f616473)](https://packagist.org/packages/lecturize/laravel-addresses)[![License](https://camo.githubusercontent.com/0df0da186e9efb74609f7b1387253ecfec9218861fde3076a260681ba31cbfb9/68747470733a2f2f706f7365722e707567782e6f72672f6c6563747572697a652f6c61726176656c2d6164647265737365732f6c6963656e7365)](https://packagist.org/packages/lecturize/laravel-addresses)

Laravel Addresses
=================

[](#laravel-addresses)

Simple address and contact management for Laravel with automatical geocoding to add longitude and latitude.

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

[](#installation)

Require the package from your `composer.json` file

```
"require": {
	"lecturize/laravel-addresses": "^1.1"
}
```

and run `$ composer update` or both in one with `$ composer require lecturize/laravel-addresses`.

Configuration &amp; Migration
-----------------------------

[](#configuration--migration)

```
$ php artisan vendor:publish --provider="Lecturize\Addresses\AddressesServiceProvider"
```

This will publish the config file to `config/lecturize.php` and some migration files, that you'll have to run:

```
$ php artisan countries:migration
$ php artisan migrate
```

For migrations to be properly published ensure that you have added the directory `database/migrations` to the classmap in your projects `composer.json`.

Check out [Webpatser\\Countries](https://github.com/webpatser/laravel-countries) readme to see how to seed their countries data to your database.

Usage
-----

[](#usage)

First, add our `HasAddresses` trait to your model.

```

```

##### Add an Address to a Model

[](#add-an-address-to-a-model)

```
$post = Post::find(1);
$post->addAddress([
    'street'     => '123 Example Drive',
    'city'       => 'Vienna',
    'post_code'  => '1110',
    'country'    => 'AT', // ISO-3166-2 or ISO-3166-3 country code
    'is_primary' => true, // optional flag
]);
```

Alternativly you could do...

```
$address = [
    'street'     => '123 Example Drive',
    'city'       => 'Vienna',
    'post_code'  => '1110',
    'country'    => 'AT', // ISO-3166-2 or ISO-3166-3 country code
    'is_primary' => true, // optional flag
];
$post->addAddress($address);
```

Available attributes are `street`, `street_extra`, `city`, `post_code`, `state`, `country`, `state`, `notes` (for internal use). You can also use custom flags like `is_primary`, `is_billing` &amp; `is_shipping`. Optionally you could also pass `lng` and `lat`, in case you deactivated the included geocoding functionality and want to add them yourself.

##### Check if Model has Addresses

[](#check-if-model-has-addresses)

```
if ($post->hasAddresses()) {
    // Do something
}
```

##### Get all Addresses for a Model

[](#get-all-addresses-for-a-model)

```
$addresses = $post->addresses()->get();
```

##### Get primary/billing/shipping Addresses

[](#get-primarybillingshipping-addresses)

```
$address = $post->getPrimaryAddress();
$address = $post->getBillingAddress();
$address = $post->getShippingAddress();
```

##### Update an Address for a Model

[](#update-an-address-for-a-model)

```
$address = $post->addresses()->first(); // fetch the address

$post->updateAddress($address, $new_attributes);
```

##### Delete an Address from a Model

[](#delete-an-address-from-a-model)

```
$address = $post->addresses()->first(); // fetch the address

$post->deleteAddress($address); // delete by passing it as argument
```

##### Delete all Addresses from a Model

[](#delete-all-addresses-from-a-model)

```
$post->flushAddresses();
```

Contacts
--------

[](#contacts)

First, add our `HasContacts` trait to your model.

```

```

##### Add a Contact to a Model

[](#add-a-contact-to-a-model)

```
$post = Team::find(1);
$post->addContact([
    'first_name' => 'Alex',
    'website'    => 'https://twitter.com/AMPoellmann',
    'is_primary' => true, // optional flag
]);
```

##### Relate Addresses with Contacts

[](#relate-addresses-with-contacts)

Above all, `addresses` and `contacts` can be connected with an optional One To Many relationship. Like so you could assign multiple contacts to an address and retrieve them like so:

```
$address = config('lecturize.addresses.model', \Lecturize\Addresses\Models\Address::class)::find(1);
$contacts = $address->contacts;

foreach ($contacts as $contact) {
    //
}
```

```
$contact = config('lecturize.contacts.model', \Lecturize\Addresses\Models\Contact::class)::find(1)
                  ->contacts()
                  ->first();
```

```
$contact = config('lecturize.contacts.model', \Lecturize\Addresses\Models\Contact::class)::find(1);

return $contact->address->getHtml();
```

##### Geocoding

[](#geocoding)

The address model provides a method `geocode()` which will try to fetch longitude and latitude through the Google Maps API. Please make sure to add your key within the services config file at `services.google.maps.key`. If you set the option `lecturize.addresses.geocode` to `true`, the package will automatically fire the `geocode()` method whenever an addresses model is saved (precisely we hook into the `saving` event).

Changelog
---------

[](#changelog)

- \[2021-02-02\] **v1.0** The `geocode` configuration option now defaults to `false`.
- \[2022-05-16\] **v1.1** Updated dependencies to PHP 8 and Laravel 8/9 - for older versions please refer to v1.0.
- \[2023-02-21\] **v1.2** Laravel 10 support.
- \[2023-09-21\] **v1.3** Support custom models for addresses and contacts, thanks to @bfiessinger. The geocoding feature now requires a Google Maps key, see 'Geocoding' above. Also, @bfiessinger has added fallback support for flags, see pull request #40 for further info.
- \[in-progress\] **v1.4** Added additional contact fields to the addresses table, to allow for easier standalone usage (without the contacts model). This is intended to reduce the complexity of relationships and queries, that before were necessary e.g. to generate a shipping label from address and contact.

License
-------

[](#license)

Licensed under [MIT license](http://opensource.org/licenses/MIT).

Author
------

[](#author)

**Handcrafted with love by [Alexander Manfred Poellmann](https://twitter.com/AMPoellmann) in Vienna &amp; Rome.**

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

602d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3dab9044ddf7f0c040a2f49bf3ba07dbb53d609173d3af8a92316224066834be?d=identicon)[ElbaCoder](/maintainers/ElbaCoder)

---

Top Contributors

[![AlexanderPoellmann](https://avatars.githubusercontent.com/u/6631793?v=4)](https://github.com/AlexanderPoellmann "AlexanderPoellmann (148 commits)")[![bfiessinger](https://avatars.githubusercontent.com/u/41627893?v=4)](https://github.com/bfiessinger "bfiessinger (8 commits)")[![AlperenElbasan](https://avatars.githubusercontent.com/u/35299672?v=4)](https://github.com/AlperenElbasan "AlperenElbasan (3 commits)")[![jonerickson](https://avatars.githubusercontent.com/u/3356740?v=4)](https://github.com/jonerickson "jonerickson (1 commits)")

---

Tags

laraveladdressescontactslecturize

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alperenelbasan-laravel-addresses/health.svg)

```
[![Health](https://phpackages.com/badges/alperenelbasan-laravel-addresses/health.svg)](https://phpackages.com/packages/alperenelbasan-laravel-addresses)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[lecturize/laravel-addresses

Simple address and contact management for Laravel.

20164.1k](/packages/lecturize-laravel-addresses)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
