addMediaCollection('images'); } protected function casts(): array { return [ 'price' => 'decimal:2', 'stock' => 'decimal:4', ]; } public function priceFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format((float) $this->price, 0, ',', '.'), ); } public function stockFormatted(): Attribute { return Attribute::make( get: function () { $formatted = rtrim(rtrim(number_format((float) $this->stock, 4, ',', '.'), '0'), ','); return "{$formatted} {$this->rawMaterial->unit->abbreviation()}"; }, ); } public function priceInput(): Attribute { return Attribute::make( get: fn () => (string) (int) $this->price, ); } public function stockInput(): Attribute { return Attribute::make( get: fn () => rtrim(rtrim(number_format((float) $this->stock, 4, '.', ''), '0'), '.'), ); } public function rawMaterial(): BelongsTo { return $this->belongsTo(RawMaterial::class); } public function cuttingMaterials(): HasMany { return $this->hasMany(CuttingMaterial::class); } }