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
EachLunar\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 theStorefrontSession 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 theaddresses 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
Updating the Address
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.Address model implements the Addressable interface, so it can be passed directly to setBillingAddress() and setShippingAddress():
Address Fields Reference
TheLunar\Models\Address model has the following fields:
Routes
Putting It All Together
Here is a complete controller for address management:Next Steps
- Review the Addresses reference for the full list of address fields and the Country model.
- Review the Customers reference for customer model details and the user-customer relationship.
- Review the Checkout guide for how addresses are used during the checkout flow.
- Review the Order History guide for building an order history page.