$this->id, 'sku' => $this->when($this->relationLoaded('sku') && $this->sku, function () { return [ 'id' => $this->sku->id, 'name' => $this->sku->name, 'cover' => (string) $this->sku->cover, 'sell_price' => $this->sku->sell_price, 'vip_price' => (string) $this->sku->vip_price, 'specs' => array_values((array) $this->sku->specs), 'stock' => (int) $this->sku->saleable_stock, 'is_online' => $this->sku->isOnline(), ]; }, [ 'id' => $this->id, 'name' => $this->name, 'cover' => (string) $this->cover, 'sell_price' => $this->sell_price, 'vip_price' => (string) $this->vip_price, 'specs' => array_values((array) $this->specs), 'stock' => 0, 'is_online' => false, ]), 'quantity' => $this->quantity, ]; } }