*/ use HasFactory, Notifiable, HasRolesAndPermissions, LogsActivity; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'email', 'password', 'password_changed_at', 'employee_id', 'phone', 'department', 'position', 'branch_code', 'hire_date', 'salary', 'status', 'emergency_contact_name', 'emergency_contact_phone', 'address', 'date_of_birth', 'national_id', 'last_login_at', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'password_changed_at' => 'datetime', 'hire_date' => 'date', 'date_of_birth' => 'date', 'last_login_at' => 'datetime', 'salary' => 'decimal:2', ]; } /** * Get the user's initials */ public function initials(): string { return Str::of($this->name) ->explode(' ') ->take(2) ->map(fn ($word) => Str::substr($word, 0, 1)) ->implode(''); } /** * Get the branch that the user belongs to */ public function branch() { return $this->belongsTo(Branch::class, 'branch_code', 'code'); } /** * Check if user is a service supervisor */ public function isServiceSupervisor(): bool { return $this->hasRole('service_supervisor'); } /** * Check if user is a service coordinator */ public function isServiceCoordinator(): bool { return $this->hasRole('service_coordinator'); } /** * Check if user is parts manager */ public function isPartsManager(): bool { return $this->hasRole('parts_manager'); } /** * Check if user is service advisor */ public function isServiceAdvisor(): bool { return $this->hasRole('service_advisor'); } /** * Get the options for logging activities. */ public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logOnly(['name', 'email', 'employee_id', 'phone', 'department', 'position', 'branch_code', 'status']) ->logOnlyDirty() ->dontSubmitEmptyLogs(); } }