'integer', 'stock' => 'decimal:4', ]; } // 3. Attribute public function priceFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->price, 0, ',', '.'), ); } public function priceInput(): Attribute { return Attribute::make( get: fn () => (string) $this->price, ); } public function stockFormatted(): Attribute { return Attribute::make( get: function () { $formatted = rtrim(rtrim(number_format((float) $this->stock, 4, ',', '.'), '0'), ','); $unitAbbreviation = $this->attributes['unit_abbreviation'] ?? $this->rawMaterial?->unit?->abbreviation(); return "{$formatted} {$unitAbbreviation}"; }, ); } public function stockInput(): Attribute { return Attribute::make( get: fn () => rtrim(rtrim(number_format((float) $this->stock, 4, '.', ''), '0'), '.'), ); } // 4. Other Methods public static function mediaModuleName(): string { return 'raw-material'; } public function registerMediaCollections(): void { $this->addMediaCollection('images'); } // 5. Relation public function cuttingMaterials(): HasMany { return $this->hasMany(CuttingMaterial::class); } public function purchaseItems(): HasMany { return $this->hasMany(PurchaseItem::class); } public function rawMaterial(): BelongsTo { return $this->belongsTo(RawMaterial::class)->withTrashed(); } }