belongsTo(\App\Models\Invoice::class, 'invoice_id'); } public function customer() { return $this->belongsTo(\App\Models\Customer::class); } public function type() { return $this->belongsTo(\App\Models\Type::class, 'invoice_type'); } public function os() { return $this->belongsTo(Os::class, 'os_id'); } public function addons() { return $this->hasMany(InvoiceAddons::class, 'invoice_item_id')->with('addonItems'); } public function hosting() { return $this->belongsTo(Hosting::class, 'product_id'); } public function vps() { return $this->belongsTo(VPS::class, 'product_id'); } // Remove the dynamic product relationship as it causes issues with eager loading public function getProductAttribute() { return match ($this->product_type) { 3 => $this->hosting, 4 => $this->vps, default => null, }; } public function getBilling() { $months = $this->attributes['months'] ?? 0; return match ($months) { 0 => "One Time", 1 => "Monthly", 3 => "Quarterly", 6 => "Semi-Annually", 12 => "Annually", 24 => "2 Years", 36 => "3 Years", default => $months . " Months" }; } public function GetRelidProduct() { $model = null; switch ($this->type_id) { case 3: $model = ModuleHosting::with('server')->find($this->relid); break; case 4: $model = ModuleVmware::with('ipAddress')->find($this->relid); break; default: break; } return $model; } }