*/ use HasApiTokens, HasFactory, Notifiable; protected $fillable = ['public_id', 'name', 'email', 'avatar_url', 'password']; protected $hidden = ['password', 'remember_token']; protected function casts(): array { return ['email_verified_at' => 'datetime', 'password' => 'hashed']; } /** Active team memberships (accounts this user can act within as a member). */ public function memberships(): HasMany { return $this->hasMany(HostingTeamMember::class, 'user_id') ->where('status', HostingTeamMember::STATUS_ACTIVE); } /** Can this user act within the given account (own it, or active member)? */ public function canAccessAccount(int $accountId): bool { return $accountId === $this->id || $this->memberships()->where('account_id', $accountId)->exists(); } /** Owner Users for every account this user can act in (self first). */ public function accessibleAccounts(): Collection { $ids = $this->memberships()->pluck('account_id')->all(); return collect([$this])->merge(self::whereIn('id', $ids)->get())->unique('id')->values(); } }