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

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

joepages/laravel-addresses
==========================

Polymorphic addresses package for Laravel - Attach N addresses to any model

v1.1.0(3mo ago)0353↓50%MITPHPPHP ^8.2CI passing

Since Feb 2Pushed 3mo agoCompare

[ Source](https://github.com/joepages/laravel-addresses)[ Packagist](https://packagist.org/packages/joepages/laravel-addresses)[ Docs](https://github.com/joepages/laravel-addresses)[ RSS](/packages/joepages-laravel-addresses/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

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

[](#laravel-addresses)

[![Tests](https://github.com/joepages/laravel-addresses/actions/workflows/tests.yml/badge.svg)](https://github.com/joepages/laravel-addresses/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/b357483bbd5bf73e71f406ba0a48dbc01511528ae00042d67adb30ca52e1275e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f6570616765732f6c61726176656c2d6164647265737365732e737667)](https://packagist.org/packages/joepages/laravel-addresses)[![License](https://camo.githubusercontent.com/a715aa6e8247be63f65a00ec6b4fd4a9420b121bb242d6f9b5ca7bf0eb7cced2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a6f6570616765732f6c61726176656c2d6164647265737365732e737667)](https://packagist.org/packages/joepages/laravel-addresses)

Polymorphic addresses for Laravel. Attach multiple addresses to any Eloquent model with full CRUD, bulk sync, primary address management, geolocation support, and multi-tenancy awareness.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

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

[](#installation)

```
composer require joepages/laravel-addresses
```

Run the install command to publish the config and migrations:

```
php artisan addresses:install
php artisan migrate
```

The installer auto-detects [stancl/tenancy](https://tenancyforlaravel.com/) and publishes migrations to `database/migrations/tenant/` when present.

### Install options

[](#install-options)

```
php artisan addresses:install --force            # Overwrite existing files
php artisan addresses:install --skip-migrations  # Only publish config
```

Quick Start
-----------

[](#quick-start)

### 1. Add the trait to your model

[](#1-add-the-trait-to-your-model)

```
use Addresses\Concerns\HasAddresses;

class Facility extends Model
{
    use HasAddresses;
}
```

### 2. Add the controller trait

[](#2-add-the-controller-trait)

```
use Addresses\Concerns\ManagesAddresses;

class FacilityController extends BaseApiController
{
    use ManagesAddresses;
}
```

### 3. Register routes

[](#3-register-routes)

```
Route::addressRoutes('facilities', FacilityController::class);
```

This registers the following routes:

MethodURIActionGET`/facilities/{facility}/addresses``listAddresses`POST`/facilities/{facility}/addresses``storeAddress`PUT`/facilities/{facility}/addresses/{address}``updateAddress`DELETE`/facilities/{facility}/addresses/{address}``deleteAddress`Model Trait API
---------------

[](#model-trait-api)

The `HasAddresses` trait provides three relationships on your model:

```
$facility->addresses;               // All addresses (MorphMany)
$facility->primaryAddress;          // Primary address (MorphOne)
$facility->addressesOfType('work'); // Filtered by type (MorphMany)
```

Address Model
-------------

[](#address-model)

### Fields

[](#fields)

FieldTypeDescription`type`stringAddress type (`home`, `work`, `billing`, `shipping`, `mailing`, `other`)`is_primary`booleanWhether this is the primary address`address_line_1`stringStreet address line 1`address_line_2`string|nullStreet address line 2`city`stringCity`state`string|nullState/province`postal_code`string|nullZIP/postal code`country_code`string2-3 letter country code`latitude`float|nullLatitude coordinate`longitude`float|nullLongitude coordinate`metadata`array|nullCustom JSON data### Scopes

[](#scopes)

```
Address::primary()->get();            // Only primary addresses
Address::ofType('billing')->get();    // Filter by type
Address::forModel($facility)->get();  // All addresses for a specific model
```

### Helpers

[](#helpers)

```
$address->markAsPrimary();    // Sets as primary, unsets all others for the same parent
$address->full_address;       // "123 Main St, Apt 4, Springfield, IL, 62701, US"
$address->hasCoordinates();   // true if latitude and longitude are set
```

Controller Trait
----------------

[](#controller-trait)

The `ManagesAddresses` trait provides two integration modes:

### Standalone CRUD

[](#standalone-crud)

Use the `storeAddress`, `updateAddress`, `deleteAddress`, and `listAddresses` methods directly via the route macro.

### Bulk Sync via BaseApiController

[](#bulk-sync-via-baseapicontroller)

When your controller extends `BaseApiController`, the `attachAddress()` method is called automatically during `store()` and `update()`. Send an `addresses` array in the request body to create, update, and delete addresses in a single operation:

```
{
  "name": "Main Facility",
  "addresses": [
    {
      "id": 1,
      "address_line_1": "123 Updated St",
      "city": "Springfield",
      "country_code": "US"
    },
    {
      "address_line_1": "456 New Ave",
      "city": "Shelbyville",
      "country_code": "US",
      "type": "billing",
      "is_primary": true
    }
  ]
}
```

- Records **with an `id`** are updated
- Records **without an `id`** are created
- Existing records **not included** in the array are deleted

API Resource
------------

[](#api-resource)

Add addresses to your JSON responses:

```
use Addresses\Concerns\WithAddressesResource;

class FacilityResource extends JsonResource
{
    use WithAddressesResource;

    public function toArray($request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            ...$this->addressesResource(),
        ];
    }
}
```

Validation
----------

[](#validation)

The `AddressRequest` form request validates:

FieldRules`address_line_1`required, string, max:255`address_line_2`nullable, string, max:255`city`required, string, max:255`state`nullable, string, max:255`postal_code`nullable, string, max:20`country_code`required, string, min:2, max:3`type`sometimes, string (validated against config when `allow_custom_types` is false)`is_primary`sometimes, boolean`latitude`nullable, numeric, -90 to 90`longitude`nullable, numeric, -180 to 180`metadata`nullable, arrayConfiguration
-------------

[](#configuration)

```
// config/addresses.php

return [
    // 'auto' detects stancl/tenancy, 'single' or 'multi' to force
    'tenancy_mode' => 'auto',

    // Allowed address types
    'types' => ['home', 'work', 'billing', 'shipping', 'mailing', 'other'],

    // Default type when none specified
    'default_type' => 'home',

    // When false, only types in the 'types' array are accepted
    'allow_custom_types' => true,
];
```

Database Schema
---------------

[](#database-schema)

```
CREATE TABLE addresses (
    id              BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
    addressable_type VARCHAR(255) NOT NULL,
    addressable_id   BIGINT UNSIGNED NOT NULL,
    type            VARCHAR(50) DEFAULT 'home',
    is_primary      BOOLEAN DEFAULT FALSE,
    address_line_1  VARCHAR(255) NOT NULL,
    address_line_2  VARCHAR(255) NULL,
    city            VARCHAR(255) NOT NULL,
    state           VARCHAR(255) NULL,
    postal_code     VARCHAR(255) NULL,
    country_code    VARCHAR(3) NOT NULL,
    latitude        DECIMAL(10,7) NULL,
    longitude       DECIMAL(10,7) NULL,
    metadata        JSON NULL,
    created_at      TIMESTAMP NULL,
    updated_at      TIMESTAMP NULL,

    INDEX (addressable_type, addressable_id),
    INDEX (type),
    INDEX (is_primary),
    INDEX (country_code)
);
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance80

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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

Every ~0 days

Total

2

Last Release

106d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8759bf04f295d7d6dcaf23c6defdaee79de5fb85d7a4fbd3fe4e38a885bc7134?d=identicon)[joepages](/maintainers/joepages)

---

Tags

laraveladdressesmulti-tenancypolymorphic

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/joepages-laravel-addresses/health.svg)](https://phpackages.com/packages/joepages-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)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)

PHPackages © 2026

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