orders = Order::where('customer_id', auth()->user()->customer->id) ->with(['items.orderable']) ->latest() ->get() ->map(function ($order) { $order->status_color = $order->status->color(); $order->status_label = $order->status->label(); $order->formatted_created_at = formatDateLocalized($order->created_at); $order->formatted_total = formatCurrencyNumber($order->total, 'Rp'); $order->total_items_count = $order->items->count(); $order->preview_items = $order->items->take(2)->map(function ($item) { return [ 'name' => $item->orderable->name ?? 'Unknown Item', 'quantity_label' => ! empty($item->quality) ? $item->quality : 'x'.$item->quantity, ]; }); $order->remaining_items_count = max(0, $order->items->count() - 2); return $order; }) ->toArray(); } public function render(): View { return view('livewire.member.order-histories', [ 'pageTitle' => 'Riwayat Pesanan', 'pageDescription' => 'Lihat riwayat pesanan dan status pembayaran Anda.', ]); } }