'decimal:4', 'subtotal' => 'integer', 'unit_price' => 'integer', ]; } // 3. Attribute public function quantityFormatted(): Attribute { return Attribute::make( get: function () { $formatted = rtrim(rtrim(number_format((float) $this->quantity, 4, ',', '.'), '0'), ','); $unitAbbreviation = $this->attributes['unit_abbreviation'] ?? $this->rawMaterialPrice?->rawMaterial?->unit?->abbreviation(); return "{$formatted} {$unitAbbreviation}"; }, ); } public function quantityInput(): Attribute { return Attribute::make( get: fn () => rtrim(rtrim(number_format((float) $this->quantity, 4, '.', ''), '0'), '.'), ); } public function subtotalFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->subtotal, 0, ',', '.'), ); } public function unitAbbreviation(): Attribute { return Attribute::make( get: fn () => $this->attributes['unit_abbreviation'] ?? $this->rawMaterialPrice?->rawMaterial?->unit?->abbreviation(), ); } public function unitPriceFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->unit_price, 0, ',', '.'), ); } // 4. Relation public function purchase(): BelongsTo { return $this->belongsTo(Purchase::class)->withTrashed(); } public function rawMaterialPrice(): BelongsTo { return $this->belongsTo(RawMaterialPrice::class)->withTrashed(); } public function user(): BelongsTo { return $this->belongsTo(User::class)->withTrashed(); } }