'datetime', 'password' => 'hashed', 'status' => UserStatus::class, ]; } protected static function newFactory(): Factory { return \Database\Factories\UserFactory::new(); } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logFillable() ->logExcept(['password']) ->logOnlyDirty() ->dontSubmitEmptyLogs(); } public function canAccessPanel(Panel $panel): bool { return match ($panel->getId()) { 'admin' => $this->hasRole('admin'), default => false, }; } public function getTenants(Panel $panel): Collection { return collect([$this]); } public function canAccessTenant(Model $tenant): bool { return $tenant->getKey() === $this->getKey(); } public function listings() { return $this->hasMany(Listing::class); } public function profile() { return $this->hasOne(Profile::class); } public function favoriteListings() { return $this->belongsToMany(Listing::class, 'favorite_listings')->withTimestamps(); } public function favoriteSellers() { return $this->belongsToMany(self::class, 'favorite_sellers', 'user_id', 'seller_id')->withTimestamps(); } public function favoriteSearches() { return $this->hasMany(FavoriteSearch::class); } public function buyerConversations() { return $this->hasMany(Conversation::class, 'buyer_id'); } public function sellerConversations() { return $this->hasMany(Conversation::class, 'seller_id'); } public function sentConversationMessages() { return $this->hasMany(ConversationMessage::class, 'sender_id'); } public function canImpersonate(): bool { return $this->hasRole('admin'); } public function canBeImpersonated(): bool { return ! $this->hasRole('admin'); } public function getFilamentAvatarUrl(): ?string { return filled($this->avatar_url) ? Storage::disk('public')->url($this->avatar_url) : null; } public function getDisplayName(): string { return trim((string) ($this->name ?: $this->email ?: 'User')); } public function getEmail(): string { return trim((string) $this->email); } public function toggleFavoriteListing(Listing $listing): bool { $isFavorite = $this->favoriteListings()->whereKey($listing->getKey())->exists(); if ($isFavorite) { $this->favoriteListings()->detach($listing->getKey()); return false; } $this->favoriteListings()->syncWithoutDetaching([$listing->getKey()]); return true; } public function toggleFavoriteSeller(self $seller): bool { if ((int) $seller->getKey() === (int) $this->getKey()) { return false; } $isFavorite = $this->favoriteSellers()->whereKey($seller->getKey())->exists(); if ($isFavorite) { $this->favoriteSellers()->detach($seller->getKey()); return false; } $this->favoriteSellers()->syncWithoutDetaching([$seller->getKey()]); return true; } }