'date', 'total' => 'integer', ]; } protected function totalFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->total, 0, ',', '.'), ); } public function items(): HasMany { return $this->hasMany(PurchaseItem::class); } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logOnly(['purchase_date', 'total', 'note']) ->logOnlyDirty() ->useLogName('Pembelian'); } public function tapActivity(Activity $activity, string $eventName) { $activity->description = match ($eventName) { 'created' => 'TAMBAH', 'updated' => 'UBAH', 'deleted' => 'HAPUS', default => $activity->description, }; if (isset($activity->properties['attributes'])) { $attributeMap = [ 'purchase_date' => 'Tanggal Beli', 'total' => 'Total', 'note' => 'Catatan', ]; $properties = $activity->properties->toArray(); $localizeValues = function ($attrs) use ($attributeMap) { $newAttrs = []; foreach ($attrs as $key => $value) { $label = $attributeMap[$key] ?? $key; $newAttrs[$label] = $value; } return $newAttrs; }; $properties['attributes'] = $localizeValues($properties['attributes']); if (isset($properties['old'])) { $properties['old'] = $localizeValues($properties['old']); } $activity->properties = collect($properties); } } }