public_id === $ownerRef; } public function memberFor(User $actor, string $ownerRef): ?WooStoreMember { if ($this->isAccountOwner($actor, $ownerRef)) { return null; } return WooStoreMember::query() ->where('owner_ref', $ownerRef) ->where('user_ref', $actor->public_id) ->first(); } /** @return list */ public function accessibleStoreIds(User $actor, string $ownerRef): ?array { if ($this->isAccountOwner($actor, $ownerRef)) { return null; } $ids = WooStoreMember::query() ->where('owner_ref', $ownerRef) ->where('user_ref', $actor->public_id) ->pluck('woo_store_id') ->map(fn ($id) => (int) $id) ->unique() ->values() ->all(); abort_if($ids === [], 403, 'You do not have access to this Woo Manager account.'); return $ids; } public function canAccessStore(User $actor, string $ownerRef, int $storeId): bool { $scope = $this->accessibleStoreIds($actor, $ownerRef); return $scope === null || in_array($storeId, $scope, true); } public function canManageStoreTeam(?WooStoreMember $member, string $ownerRef, User $actor): bool { return $this->isAccountOwner($actor, $ownerRef); } /** @return Collection */ public function membershipsFor(User $actor): Collection { return WooStoreMember::query() ->where('user_ref', $actor->public_id) ->with('store') ->get(); } }