$this->id, 'unit_id' => $this->unit_id, 'class_package_id' => $this->class_package_id, 'name' => $this->name, 'quantity_classes' => $this->quantity_classes, 'contract_value' => $this->contract_value, 'contract_material_value' => $this->contract_material_value, 'contract_register_value' => $this->contract_register_value, 'contrat_discount_value' => $this->contrat_discount_value, 'visible' => $this->visible, 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'), 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'), 'materials' => $this->whenLoaded('products', fn() => $this->products->map(fn($item) => [ 'product_id' => $item->product_id, 'name' => $item->product?->name, 'quantity' => $item->quantity, 'price' => (float) $item->price, ]) ), ]; } }