user(); $serverTypes = $this->serverTypes(); $orders = CustomerHostingOrder::query() ->forUser($user->id) ->whereHas('product', fn ($q) => $q->whereIn('type', $serverTypes)) ->with('product') ->latest() ->get(); $activeOrders = $orders->where('status', CustomerHostingOrder::STATUS_ACTIVE); $pendingOrders = $orders->whereIn('status', [ CustomerHostingOrder::STATUS_PENDING_PAYMENT, CustomerHostingOrder::STATUS_PENDING_APPROVAL, CustomerHostingOrder::STATUS_APPROVED, CustomerHostingOrder::STATUS_PROVISIONING, ]); return view('servers.dashboard', [ 'orders' => $orders, 'activeCount' => $activeOrders->count(), 'vpsCount' => $activeOrders->filter(fn (CustomerHostingOrder $order) => $order->product?->type === HostingProduct::TYPE_VPS)->count(), 'dedicatedCount' => $activeOrders->filter(fn (CustomerHostingOrder $order) => $order->product?->type === HostingProduct::TYPE_DEDICATED)->count(), 'pendingOrderCount' => $pendingOrders->count(), 'recent' => $orders->take(8), 'pendingOrders' => $pendingOrders->take(5), ]); } /** @return list */ private function serverTypes(): array { return [ HostingProduct::TYPE_VPS, HostingProduct::TYPE_DEDICATED, ]; } }