*/ public function broadcastOn(): array { return [new PresenceChannel('room.1')]; } /** * 广播事件名(前端监听 .horse.settled)。 */ public function broadcastAs(): string { return 'horse.settled'; } /** * 广播数据。 * * @return array */ public function broadcastWith(): array { // 找出获胜马匹的名称 $horses = $this->race->horses ?? []; $winnerName = '未知'; foreach ($horses as $horse) { if (($horse['id'] ?? 0) === $this->race->winner_horse_id) { $winnerName = ($horse['emoji'] ?? '').' '.($horse['name'] ?? ''); break; } } return [ 'race_id' => $this->race->id, 'winner_horse_id' => $this->race->winner_horse_id, 'winner_name' => $winnerName, 'total_pool' => $this->race->total_pool, 'settled_at' => $this->race->settled_at?->toIso8601String(), ]; } }