'boolean', ]; } #[Scope] protected function active(Builder $query): void { $query->where('is_active', true); } #[Scope] protected function inactive(Builder $query): void { $query->where('is_active', false); } public function getSlugOptions(): SlugOptions { return SlugOptions::create() ->generateSlugsFrom('name') ->saveSlugsTo('slug'); } public function products(): BelongsToMany { return $this->belongsToMany(Product::class); } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logOnly(['name', 'is_active']) ->logOnlyDirty() ->useLogName('Kategori'); } 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 = [ 'name' => 'Nama', 'is_active' => 'Status', ]; $properties = $activity->properties->toArray(); $localizeValues = function ($attrs) use ($attributeMap) { $newAttrs = []; foreach ($attrs as $key => $value) { $label = $attributeMap[$key] ?? $key; $displayValue = $value; if ($key === 'is_active') { $displayValue = $value ? 'Aktif' : 'Tidak Aktif'; } $newAttrs[$label] = $displayValue; } return $newAttrs; }; $properties['attributes'] = $localizeValues($properties['attributes']); if (isset($properties['old'])) { $properties['old'] = $localizeValues($properties['old']); } $activity->properties = collect($properties); } } }