workspace; $existingAccountIds = $post->postPlatforms()->pluck('social_account_id')->filter(); $missingAccounts = $workspace->socialAccounts() ->active() ->whereNotIn('id', $existingAccountIds) ->get(); foreach ($missingAccounts as $account) { $post->postPlatforms()->create([ 'social_account_id' => $account->id, 'platform' => $account->platform->value, 'platform_name' => $account->accountDisplayName(), 'platform_username' => $account->username, 'platform_avatar' => $account->getRawOriginal('avatar_url'), 'content_type' => ContentType::defaultFor($account->platform), 'status' => PostPlatformStatus::Pending, 'enabled' => false, ]); } } }