*/ use HasFactory, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable; protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'helpdesk_agent' => 'boolean', 'helpdesk_admin' => 'boolean', ]; } public function initials(): string { $initials = Str::initials($this->name, true); return Str::length($initials) > 1 ? Str::substr($initials, 0, 1).Str::substr($initials, -1) : $initials; } public function gravatarUrl(int $size = 160): string { $email = strtolower(trim((string) $this->email)); $hash = hash('sha256', $email); return 'https://www.gravatar.com/avatar/'.$hash .'?s='.max(1, min($size, 2048)) .'&d=404&r=g'; } public function roles(): BelongsToMany { return $this->belongsToMany( Role::class, 'user_management_role_user', 'user_id', 'role_id' ); } public function hasRole(string $role): bool { return $this->roles()->where('slug', $role)->exists(); } public function hasPermission(string $permission): bool { return $this->roles() ->whereHas('permissions', static fn ($query) => $query->where('slug', $permission)) ->exists(); } public function isHelpdeskAdmin(): bool { return (bool) $this->helpdesk_admin; } public function isHelpdeskAgent(): bool { return $this->isHelpdeskAdmin() || (bool) $this->helpdesk_agent; } public function isAdmin(): bool { return $this->isHelpdeskAdmin(); } public function isAgent(): bool { return $this->isHelpdeskAgent(); } }