@php // --- Extract embed URL based on platform --- $embedUrl = null; $platform = strtolower($video->platform ?? ''); $rawUrl = $video->embed_url ?? ''; if ($platform === 'youtube') { // Matches standard youtube urls if (preg_match('/(?:youtu\.be\/|youtube\.com\/watch\?v=|youtube\.com\/embed\/)([A-Za-z0-9_\-]{11})/', $rawUrl, $matches)) { $embedUrl = 'https://www.youtube.com/embed/' . $matches[1]; } } elseif ($platform === 'vimeo') { if (preg_match('/vimeo\.com\/(\d+)/', $rawUrl, $matches)) { $embedUrl = 'https://player.vimeo.com/video/' . $matches[1]; } elseif (preg_match('/player\.vimeo\.com\/video\/(\d+)/', $rawUrl, $matches)) { $embedUrl = $rawUrl; } } @endphp