*/ use HasApiTokens, HasFactory, HasMedia, HasUuids, HasWorkspace, Notifiable; /** * @var list */ protected $fillable = [ 'name', 'email', 'password', 'google_id', 'github_id', 'account_id', 'current_workspace_id', 'email_verified_at', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'registration_ip', 'persona', 'goals', 'referral_source', ]; /** * @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', 'persona' => Persona::class, 'goals' => 'array', 'referral_source' => ReferralSource::class, ]; } 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 { if (! $this->account_id) { return false; } if ($this->relationLoaded('account')) { return $this->id === $this->account?->owner_id; } return Account::query() ->whereKey($this->account_id) ->where('owner_id', $this->id) ->exists(); } 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, }; } }