$postPlatformIds */ public function __construct( public Workspace $workspace, public array $postPlatformIds, public int $count ) {} public function envelope(): Envelope { return new Envelope( subject: $this->subjectFor($this->count), ); } public function content(): Content { return new Content( view: 'mail.post-at-risk', with: [ 'title' => 'Posts May Fail to Publish', 'previewText' => $this->subjectFor($this->count), 'intro' => "The following social accounts in your {$this->workspace->name} workspace need to be reconnected before these scheduled posts can publish:", 'reconnectCta' => 'Please reconnect these accounts now to avoid missing your scheduled posts.', 'buttonText' => 'Reconnect Accounts', 'workspace' => $this->workspace, 'atRiskGroups' => $this->atRiskGroups(), 'url' => route('app.accounts'), ], ); } /** * @return Collection, postsLabel: string}> */ private function atRiskGroups(): Collection { if ($this->atRiskGroups !== null) { return $this->atRiskGroups; } $postPlatforms = PostPlatform::query() ->with(['socialAccount', 'post']) ->whereIn('id', $this->postPlatformIds) ->get(); return $this->atRiskGroups = $postPlatforms->groupBy('social_account_id') // The account can be null if it was hard-deleted between dispatch // and send — nothing meaningful to render for it (no platform, no // handle), so it's dropped rather than crashing the render. ->filter(fn (Collection $group) => $group->first()->socialAccount !== null) ->map(function (Collection $group) { $postCount = $group->count(); $times = $group->sortBy(fn ($pp) => $pp->post->scheduled_at) ->map(fn ($pp) => $pp->post->scheduled_at->format('H:i')) ->implode(', '); $noun = $postCount === 1 ? 'post' : 'posts'; return [ 'account' => $group->first()->socialAccount, 'postPlatforms' => $group, 'postsLabel' => "{$postCount} {$noun} scheduled: {$times} UTC", ]; })->values(); } private function subjectFor(int $count): string { $noun = $count === 1 ? 'post is' : 'posts are'; return "{$count} {$noun} at risk in {$this->workspace->name}"; } public function attachments(): array { return []; } }