*/ use HasFactory, Notifiable, TwoFactorAuthenticatable; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'user_type', 'full_name', 'national_id', 'company_name', 'company_cert_number', 'contact_person_name', 'contact_person_id', 'email', 'phone', 'password', 'status', 'preferred_language', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'national_id', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'user_type' => UserType::class, 'status' => UserStatus::class, 'email_verified_at' => 'datetime', 'two_factor_confirmed_at' => 'datetime', 'password' => 'hashed', ]; } /** * Get the user's initials. */ public function initials(): string { return Str::of($this->full_name) ->explode(' ') ->take(2) ->map(fn ($word) => Str::substr($word, 0, 1)) ->implode(''); } /** * Check if user is an admin. */ public function isAdmin(): bool { return $this->user_type === UserType::Admin; } /** * Check if user is an individual client. */ public function isIndividual(): bool { return $this->user_type === UserType::Individual; } /** * Check if user is a company client. */ public function isCompany(): bool { return $this->user_type === UserType::Company; } /** * Check if user is a client (individual or company). */ public function isClient(): bool { return $this->isIndividual() || $this->isCompany(); } /** * Scope to filter admin users. */ public function scopeAdmins($query) { return $query->where('user_type', UserType::Admin); } /** * Scope to filter client users (individual or company). */ public function scopeClients($query) { return $query->whereIn('user_type', [UserType::Individual, UserType::Company]); } /** * Scope to filter active users. */ public function scopeActive($query) { return $query->where('status', UserStatus::Active); } /** * Get the consultations for the user. */ public function consultations(): HasMany { return $this->hasMany(Consultation::class); } /** * Get the timelines for the user. */ public function timelines(): HasMany { return $this->hasMany(Timeline::class); } /** * Get the notifications for the user. */ public function customNotifications(): HasMany { return $this->hasMany(Notification::class); } /** * Get the admin logs for the user. */ public function adminLogs(): HasMany { return $this->hasMany(AdminLog::class, 'admin_id'); } /** * Get the timeline updates created by this admin. */ public function timelineUpdates(): HasMany { return $this->hasMany(TimelineUpdate::class, 'admin_id'); } }