*/ use HasApiTokens, HasFactory, Notifiable; protected $fillable = ['public_id', 'name', 'email', 'avatar_url', 'password', 'last_app_active_at']; protected $hidden = ['password', 'remember_token']; protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'last_app_active_at' => 'datetime', 'password' => 'hashed', ]; } public function memberships(): HasMany { return $this->hasMany(QrTeamMember::class, 'user_id') ->where('status', QrTeamMember::STATUS_ACTIVE); } public function canAccessAccount(int $accountId): bool { return $accountId === $this->id || $this->memberships()->where('account_id', $accountId)->exists(); } /** @return Collection */ public function accessibleAccounts(): Collection { $ids = $this->memberships()->pluck('account_id')->all(); return collect([$this])->merge(self::whereIn('id', $ids)->get())->unique('id')->values(); } public function avatarUrl(): ?string { $url = trim((string) $this->avatar_url); return $url !== '' ? $url : null; } }