*/ use HasFactory, HasMedia, HasUuids, HasWorkspace, Notifiable; /** * @var list */ protected $fillable = [ 'name', 'email', 'password', 'account_id', 'current_workspace_id', 'email_verified_at', ]; /** * @var list */ protected $hidden = [ 'password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token', ]; protected $appends = [ 'has_photo', 'photo_url', ]; public function getHasPhotoAttribute(): bool { return $this->getFirstMedia('avatar') !== null; } public function getPhotoUrlAttribute(): ?string { return $this->getFirstMediaUrl('avatar'); } protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'two_factor_confirmed_at' => 'datetime', ]; } public function notifications(): HasMany { return $this->hasMany(Notification::class); } public function notificationPreference(): HasOne { return $this->hasOne(NotificationPreference::class); } public function account(): BelongsTo { return $this->belongsTo(Account::class); } public function isAccountOwner(): bool { return $this->id === $this->account?->owner_id; } public function wantsEmailFor(NotificationType $type): bool { $preference = $this->notificationPreference; if (! $preference) { return true; } return match ($type) { NotificationType::PostPublished => $preference->post_published, NotificationType::PostFailed, NotificationType::PostPartiallyPublished => $preference->post_failed, NotificationType::AccountDisconnected => $preference->account_disconnected, NotificationType::MentionedInComment => $preference->mentioned_in_comment ?? true, default => true, }; } }