Skip to main content

Overview

The customer addresses page allows authenticated customers to 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 setting default shipping and billing addresses. 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\Models\Address belongs to a Lunar\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\Models\OrderAddress records, creating an immutable snapshot.

Resolving the Current Customer

Like all account pages, the addresses page requires an authenticated user with a linked customer. Use the StorefrontSession facade to resolve the current customer.
The StorefrontSession automatically resolves the customer from the authenticated user when the LunarUser trait is applied to the User model. See the Storefront Session reference for details on how customer 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

When setting a new default address, clear the default flag from all other addresses first to ensure only one address is the default at a time.

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. The Address model implements the Addressable interface, so it can be passed directly to setBillingAddress() and setShippingAddress():
When using a saved address at checkout, Lunar copies the address data to the cart. Changes to the saved address after checkout do not affect existing orders.

Address Fields Reference

The Lunar\Models\Address model has the following fields:

Routes

Putting It All Together

Here is a complete controller for address management:

Next Steps