belongsTo(Order::class, 'order_id'); } public function addons() { return $this->hasMany(OrderAddon::class, 'order_item_id'); } public function getProductAttribute() { // New flow: Check if product exists in Product table first if ($this->product_id) { $product = Product::find($this->product_id); if ($product) { return $product; } } // Legacy flow: fallback to old system return match ($this->product_type) { 3 => Hosting::find($this->product_id), 4 => Vps::find($this->product_id), default => null, }; } /** * Relationship: OrderItem belongs to Product (new system) */ public function product() { return $this->belongsTo(Product::class, 'product_id'); } /** * Relationship: OrderItem has pricing info */ public function pricing() { return $this->belongsTo(ProductPricings::class, 'product_pricing_id'); } public function os() { return $this->belongsTo(Os::class, 'os_id'); } }