model ->with([ 'product.servicePlan', 'addons', 'invoice.order', 'orderItem' => fn($q) => $q->with(['product.servicePlan', 'os.osGroup', 'order']), ]) ->where('customer_id', $customerId) ->orderByRaw("FIELD(status, 'active', 'pending', 'suspended', 'expired', 'cancelled', 'terminated')") ->orderBy('started_at', 'desc'); if ($productType) { $query->where('type', $productType); } return $limit === null ? $query->get() : $query->paginate($limit); } public function findActiveBySlug(string $slug) { return $this->model ->with(['osVersions.osGroup', 'category', 'pricings' => fn ($q) => $q->where('is_active', 1)]) ->where('slug', $slug) ->where('is_active', 1) ->first(); } public function getPricing(int $productId, string $billingCycle) { $product = $this->model->find($productId); if (!ProductBillingCycles::allows($product->product_type, $billingCycle)) { return null; } $pricing = $product->pricings() ->where('billing_cycle', $billingCycle) ->where('is_active', 1) ->first(); return $pricing ? $pricing->price : null; } public function getDetailService(string $uuid, int $customerId) { return $this->model ->with([ 'addons', 'orderItem.os.osGroup', 'orderItem.product', 'orderItem.order', 'vmware.ipAddress', 'hostingAccount.server', ]) ->where('uuid', $uuid) ->where('customer_id', $customerId) ->first(); } }