order('create_time', 'asc') ->order('id', 'asc') ->find(); MatchEvent::where('id', $matchId)->update([ 'live_url' => $row ? (string) $row->source_url : '', 'update_time' => time(), ]); } public static function getLiveListForApi(int $matchId): array { // MatchLive uses SoftDelete, so default queries only return non-deleted rows. $rows = MatchLive::where('match_id', $matchId) ->order('create_time', 'asc') ->order('id', 'asc') ->select() ->toArray(); foreach ($rows as &$row) { $row['stream_options'] = self::buildStreamOptions($row); $row['default_play_url'] = $row['stream_options'][0]['url'] ?? ''; } unset($row); return $rows; } public static function buildStreamOptions(array $row): array { $definitions = [ ['label' => 'M3U8', 'field' => 'play_url_m3u8'], ['label' => 'HD M3U8', 'field' => 'play_url_hd_m3u8'], ['label' => 'FLV', 'field' => 'play_url_flv'], ['label' => 'HD FLV', 'field' => 'play_url_hd_flv'], ]; $options = []; foreach ($definitions as $definition) { $url = trim((string) ($row[$definition['field']] ?? '')); if ($url === '') { continue; } $options[] = [ 'label' => $definition['label'], 'url' => $url, ]; } return $options; } }