NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Addresses for Laravel

The Address model

RoundlyConsulting\Addresses\Address is a regular Eloquent model backing the addresses table. It is non-final so you can extend it, uses HasFactory and SoftDeletes, and leaves every attribute mass-assignable ($guarded = []).

AttributeTypeNotes
idintPrimary key.
addressable_type / addressable_idstring / keyThe owner’s morph pair.
is_primaryboolCast to bool.
typeAddressTypeCast to the enum.
name?stringOptional label.
city, street, postal_code?stringThe address lines.
country_iso?stringThe stored ISO code.
country_name?stringAccessor — resolved through a CountryResolver, never stored.
meta?CollectionCollection cast over the JSON column.
created_at, updated_at, deleted_at?CarbonTimestamps and the soft-delete marker.
$address->addressable;          // the owning model (Customer, Company, …)
$address->type;                 // AddressType::Billing
$address->type->label();        // 'Billing'
$address->is_primary;           // bool
$address->country_iso;          // 'SK'
$address->country_name;         // resolved name, or null without a resolver

Meta

meta holds anything address-related that does not deserve a column — a floor, a gate code, delivery notes. It is stored as JSON and cast back to an Illuminate\Support\Collection, or null when nothing was set:

$address = $customer->newAddress()
    ->in('Bratislava')->at('Somewhere 1')->postalCode('81101')->country('SK')
    ->meta(['floor' => 3, 'gate_code' => '1234'])
    ->save();

$address->meta->get('floor');        // 3
$address->meta?->get('gate_code');  // '1234' — meta is null when none was set

Formatted label

formatted() builds a single-line label from the populated parts — name, street, postal code with city, and the country code — skipping any that are empty. Pass a separator to replace the default comma:

$payer->primaryAddress()?->formatted();
// "HQ, Somewhere 1, 81101 Bratislava, SK"

$address->formatted(' | ');
// "HQ | Somewhere 1 | 81101 Bratislava | SK"

// empty parts are skipped — the same kind of address without a name:
// "Main 2, 04001 Košice, SK"

The label uses the ISO code, not a resolved country name, so it is the same whether or not a CountryResolver is bound.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.