How Addresses Work
EachLunar\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. UseLunar\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 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
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.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 implements Lunar\Core\Contracts\Addressable, so it can be passed directly to setBillingAddress() and setShippingAddress():
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
- Review the Addresses reference for the full field list and the
Countrymodel. - 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.