Skip to main content
The customer addresses page lets an authenticated customer manage their saved addresses. These addresses can be selected during checkout to speed up the purchasing process. This guide walks through listing, creating, editing, and deleting addresses, as well as how default shipping and billing addresses work. The examples below use standard Laravel controllers and Blade templates. The same concepts apply whether the storefront is built with Livewire, Inertia, or a headless API.

How Addresses Work

Each Lunar\Core\Models\Address belongs to a Lunar\Core\Models\Customer. A customer can have any number of saved addresses, and each address can be flagged as the default for shipping, billing, or both. During checkout, saved addresses can be used to pre-fill the address forms. Addresses stored on a customer are separate from order addresses. When an order is created, the cart’s addresses are copied to the order as Lunar\Core\Models\OrderAddress records, creating an immutable snapshot.

Resolving the Current Customer

Like all account pages, the addresses page requires a resolved customer. Use Lunar\Core\Facades\StorefrontSession to get the current customer.
See the Customer Authentication guide for how a customer gets linked to the authenticated user, and the Storefront Session reference for how resolution works.

Listing Addresses

Query the customer’s addresses using the addresses relationship. Eager load the country relationship to display the country name.

Displaying the Address List

Creating an Address

The Create Form

Storing the Address

postcode is nullable on the Address model — not every country uses one. Adjust the validation rule if the storefront needs to require it for specific countries.
Lunar unsets the previous default shipping/billing address for the customer automatically, through Lunar\Core\Observers\AddressObserver. Creating or updating an address with shipping_default or billing_default set to true clears the flag from whichever address previously held it — there is no need to clear the flags manually before saving.

Editing an Address

The Edit Form

The edit form is identical in structure to the create form, with fields pre-populated from the existing address:

Updating the Address

Always verify that the address belongs to the current customer before allowing edits or deletions. Without this check, a customer could modify another customer’s address by manipulating the URL.

Deleting an Address

Using Saved Addresses at Checkout

Saved addresses can be loaded during checkout to let customers select from their existing addresses instead of entering a new one.
When a customer selects a saved address, pass it to the cart. Address implements Lunar\Core\Contracts\Addressable, so it can be passed directly to setBillingAddress() and setShippingAddress():
When using a saved address at checkout, Lunar copies the address data onto a Lunar\Core\Models\CartAddress record. Changes to the saved address afterward do not affect the cart, and once the order is placed the cart address is copied again onto an immutable OrderAddress. See the Checkout guide for the full flow.

Address Fields Reference

Lunar\Core\Models\Address has the following fields:

Routes

Putting It All Together

Here is a complete controller for address management:

Next Steps