id) ->get() ->each(function (User $affected) use ($workspace): void { $fallback = $affected->workspaces() ->where('workspaces.id', '!=', $workspace->id) ->first(); $affected->update(['current_workspace_id' => $fallback?->id]); }); $account = $workspace->account; $accountId = (string) $workspace->account_id; $workspace->delete(); $account?->syncWorkspaceQuantity(); if (PostHogService::isEnabled()) { SyncAccountUsage::dispatch($accountId, null); } } }