'hashed', 'is_active' => 'boolean', ]; } public function scopeActive(Builder $query): void { $query->where('is_active', true); } public function scopeInactive(Builder $query): void { $query->where('is_active', false); } protected function name(): Attribute { return Attribute::make( get: fn () => $this->profile?->full_name ?? $this->username ); } public function expenses(): HasMany { return $this->hasMany(Expense::class); } public function orders(): HasMany { return $this->hasMany(Order::class); } public function orderItems(): HasMany { return $this->hasMany(OrderItem::class); } public function purchaseItems(): HasMany { return $this->hasMany(PurchaseItem::class); } public function payrolls(): HasMany { return $this->hasMany(Payroll::class); } public function profile(): HasOne { return $this->hasOne(UserProfile::class); } public function salaryHistories(): HasMany { return $this->hasMany(SalaryHistory::class); } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logOnly(['username', 'is_active']) ->logOnlyDirty() ->useLogName('Pegawai'); } 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 = [ 'username' => 'Username', '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); } } }