$positions 各马匹进度 [horse_id => progress(0~100)] * @param bool $finished 是否已到终点 * @param int|null $leaderId 当前领跑马匹 ID */ public function __construct( public readonly int $raceId, public readonly array $positions, public readonly bool $finished = false, public readonly ?int $leaderId = null, ) {} /** * 广播至房间公共频道。 * * @return array<\Illuminate\Broadcasting\Channel> */ public function broadcastOn(): array { return [new PresenceChannel('room.1')]; } /** * 广播事件名(前端监听 .horse.progress)。 */ public function broadcastAs(): string { return 'horse.progress'; } /** * 广播数据。 * * @return array */ public function broadcastWith(): array { return [ 'race_id' => $this->raceId, 'positions' => $this->positions, 'finished' => $this->finished, 'leader_id' => $this->leaderId, ]; } }