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 = []).
| Attribute | Type | Notes |
|---|---|---|
id | int | Primary key. |
addressable_type / addressable_id | string / key | The owner’s morph pair. |
is_primary | bool | Cast to bool. |
type | AddressType | Cast to the enum. |
name | ?string | Optional label. |
city, street, postal_code | ?string | The address lines. |
country_iso | ?string | The stored ISO code. |
country_name | ?string | Accessor — resolved through a CountryResolver, never stored. |
meta | ?Collection | Collection cast over the JSON column. |
created_at, updated_at, deleted_at | ?Carbon | Timestamps 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 resolverMeta
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 setFormatted 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 cryptoBy 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.