PHPackages                             marshmallow/addressable - 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. marshmallow/addressable

ActiveLibrary

marshmallow/addressable
=======================

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

v1.8.0(10mo ago)07.7k↓60%1MITPHPPHP ^7.4|^8.0|^8.4CI passing

Since Jul 21Pushed 1w ago1 watchersCompare

[ Source](https://github.com/marshmallow-packages/addressable)[ Packagist](https://packagist.org/packages/marshmallow/addressable)[ Docs](https://github.com/Marshmallow-Development/)[ RSS](/packages/marshmallow-addressable/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (3)Versions (15)Used By (1)

[![alt text](https://camo.githubusercontent.com/329958cb02b7bee461fd9dcae7a0a3a34e6595669116ff441ad5ef9e77bc511c/68747470733a2f2f63646e2e6d617273686d616c6c6f772d6f66666963652e636f6d2f6d656469612f696d616765732f6c6f676f2f6d617273686d616c6c6f772e7472616e73706172656e742e7265642e706e67 "marshmallow.")](https://camo.githubusercontent.com/329958cb02b7bee461fd9dcae7a0a3a34e6595669116ff441ad5ef9e77bc511c/68747470733a2f2f63646e2e6d617273686d616c6c6f772d6f66666963652e636f6d2f6d656469612f696d616765732f6c6f676f2f6d617273686d616c6c6f772e7472616e73706172656e742e7265642e706e67)

Marshmallow Addressable
=======================

[](#marshmallow-addressable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2dc6ec9be5163f97016c2b50e4defe8035ea6d04c61c92e2f67d3e612d6ccd1f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617273686d616c6c6f772f6164647265737361626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marshmallow/addressable)[![Tests](https://camo.githubusercontent.com/6d048128eea78913030044a7a294bf463e6074f82e4980ed169eb30f1eeac6bd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d617273686d616c6c6f772d7061636b616765732f6164647265737361626c652f7068702d73796e7461782d636865636b65722e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/marshmallow-packages/addressable/actions/workflows/php-syntax-checker.yml)[![Total Downloads](https://camo.githubusercontent.com/918145e27c063bbe1072d837179c8e9d7085fe9de983841d46cd479abe08841c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617273686d616c6c6f772f6164647265737361626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marshmallow/addressable)

Add polymorphic addresses to any Eloquent model. The package ships `Address` and `AddressType` models, a `morphMany` relationship via an `Addressable` trait, automatic default-address management, country support through `marshmallow/dataset-country`, and optional Laravel Nova resources.

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

[](#installation)

Install the package via Composer:

```
composer require marshmallow/addressable
```

The service provider is auto-discovered and the package loads its own migrations, so you only need to run:

```
php artisan migrate
```

This creates the `addresses` and `address_types` tables.

Optionally publish the config file:

```
php artisan vendor:publish --provider="Marshmallow\Addressable\ServiceProvider"
```

### Address types

[](#address-types)

Run the seeder if you want some default address types in the `address_types` table. This creates a `Shipping address` and an `Invoice address`. The names are added to your database in your application locale (English and Dutch are supported for seeding).

```
php artisan db:seed --class=Marshmallow\\Addressable\\Seeders\\AddressTypeSeeder
```

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

[](#configuration)

KeyDefaultDescription`default_address_type``5`ID of the `AddressType` assigned to a new address when none is provided.Usage
-----

[](#usage)

Add the `Addressable` trait to any model you want to give addresses to:

```
use Illuminate\Database\Eloquent\Model;
use Marshmallow\Addressable\Traits\Addressable;

class User extends Model
{
    use Addressable;
}
```

### Adding addresses

[](#adding-addresses)

The trait exposes a polymorphic `addresses()` relationship:

```
$user->addresses()->create([
    'address_line_1' => 'Keizersgracht 123',
    'postal_code'    => '1015 CJ',
    'city'           => 'Amsterdam',
    'state'          => 'Noord-Holland',
    'country_id'     => $country->id,
]);
```

When an address is created without an `address_type_id`, the `default_address_type` from the config is used. The first address created for a given owner and type is automatically flagged as the default. When a default address is deleted, the next available address of the same owner is promoted to default.

### Default addresses

[](#default-addresses)

Retrieve the default address for a given type. The `$type` matches the `type` column on `AddressType` — use the `AddressType::SHIPPING` or `AddressType::INVOICE` constants:

```
use Marshmallow\Addressable\Models\AddressType;

$shippingAddress = $user->getDefaultAddress(AddressType::SHIPPING);
```

Mark a specific address as the default for its owner and type:

```
$address->makeDefault();
```

### Formatting

[](#formatting)

Render an address as a single comma-separated string (empty parts are skipped):

```
$address->getAsString();
// "Keizersgracht 123, 1015 CJ, Amsterdam, Noord-Holland"
```

### Model relationships and scopes

[](#model-relationships-and-scopes)

The `Address` model exposes the following relationships:

- `addressable()` — the owning model (morph-to).
- `addressType()` — the related `AddressType`.
- `country()` — the related country from `marshmallow/dataset-country`.

And the following query scopes: `default()`, `whereType($addressType)`, `sameOwner($owner)`, `notThisOne($owner)`.

The models, country model, address-type model, and country connection used internally can be swapped via the static properties on `Marshmallow\Addressable\Addresses`.

Nova
----

[](#nova)

Are you using Nova? There is a command to generate the Nova resources. Run the commands below and the resources will be available in Nova. The `Address` resource is hidden from the Nova navigation by default. If you want it in the navigation, add `public static $displayInNavigation = true;` to `app/Nova/Address.php`.

```
php artisan marshmallow:resource Address Addressable
php artisan marshmallow:resource AddressType Addressable
```

To make addresses visible on one of your own Nova resources, add `MorphMany::make('Addresses'),` to its `fields()` method.

Testing
-------

[](#testing)

Run the package tests during development:

```
php artisan test packages/marshmallow/addressable
```

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please report security vulnerabilities by email to  rather than via the public issue tracker.

Credits
-------

[](#credits)

- [Stef](https://marshmallow.dev)
- [All Contributors](https://github.com/marshmallow-packages/addressable/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see the [License File](LICENSE) for more information.

---

Copyright (c) 2020 marshmallow

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance78

Regular maintenance activity

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 88.9% 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

Every ~153 days

Recently: every ~389 days

Total

13

Last Release

320d ago

PHP version history (3 changes)v1.0.0PHP ^7.4

v1.4.1PHP ^7.4|^8.0

v1.8.0PHP ^7.4|^8.0|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/be33d2624e24c516e73892b0929447cc762f3622c024ab8d0d2a59042e5d2c7f?d=identicon)[marshmallow](/maintainers/marshmallow)

---

Top Contributors

[![stefvanesch](https://avatars.githubusercontent.com/u/46725619?v=4)](https://github.com/stefvanesch "stefvanesch (48 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")

---

Tags

marshmallow

### Embed Badge

![Health badge](/badges/marshmallow-addressable/health.svg)

```
[![Health](https://phpackages.com/badges/marshmallow-addressable/health.svg)](https://phpackages.com/packages/marshmallow-addressable)
```

PHPackages © 2026

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