Skip to main content

Overview

The order history page allows authenticated customers to view their past orders, check order statuses, and review the details of individual orders. This guide walks through resolving the current customer, querying their orders, displaying a paginated order list, and building an order detail page. 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.

Resolving the Current Customer

Lunar separates the concept of a Customer from Laravel’s User model. An authenticated user can be linked to one or more customers through the LunarUser trait. The StorefrontSession facade provides the current customer for the session.
If no customer is associated with the current session, getCustomer() returns null. Protect account pages with middleware that checks for an authenticated user and a valid 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 Orders

Query the customer’s orders using the orders relationship. Only orders with a placed_at value should be shown, as draft orders (where placed_at is null) have not been completed.

Displaying the Order List

Each order has its financial totals cast to Lunar\DataTypes\Price objects, so formatted() can be called directly.

Order Financial Properties

After retrieval, each Lunar\Models\Order has the following price properties: All values are Lunar\DataTypes\Price objects with access to value (integer in minor units), decimal() (float), and formatted() (currency string).

Order Detail Page

The order detail page shows the full breakdown of a specific order, including line items, addresses, and totals.
Always verify that the order belongs to the current customer. Without this check, a customer could view another customer’s order by guessing the URL.

Displaying Order Lines

Order lines hold a snapshot of each purchased item. The description field contains the product name at the time of purchase, and option holds any variant options.

Displaying Addresses

Each order stores a billing address and (for shippable orders) a shipping address. These are snapshots taken at the time of order creation and are separate from the customer’s saved addresses.

Displaying Order Totals

Tax Breakdown

To display a detailed tax breakdown:

Eager Loading for Performance

When displaying an order list, eager load the relationships needed for the list view to avoid N+1 queries:
For the detail page, load everything needed in a single query:

Routes

Putting It All Together

Here is a complete controller for the order history pages:

Next Steps