*/ 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 wooStores(): HasMany { return $this->hasMany(WooStore::class); } public function wooMemberships(): HasMany { return $this->hasMany(WooStoreMember::class, 'user_ref', 'public_id'); } public function canAccessAccount(int $accountId): bool { if ($accountId === $this->id) { return true; } $account = self::find($accountId); return $account !== null && $this->wooMemberships()->where('owner_ref', $account->public_id)->exists(); } /** @return Collection */ public function accessibleAccounts(): Collection { $ownerRefs = $this->wooMemberships()->pluck('owner_ref')->all(); return collect([$this]) ->merge(self::whereIn('public_id', $ownerRefs)->get()) ->unique('id') ->values(); } public function avatarUrl(): ?string { $url = trim((string) $this->avatar_url); return $url !== '' ? $url : null; } }