@php $platform = $record->platform ?? 'youtube'; $rawUrl = $record->embed_url ?? ''; $embedUrl = $rawUrl; if ($platform === 'youtube') { // Match watch?v= and youtu.be short links if (preg_match('/(?:youtu\.be\/|youtube\.com\/watch\?v=)([A-Za-z0-9_\-]{11})/', $rawUrl, $matches)) { $embedUrl = 'https://www.youtube.com/embed/' . $matches[1]; } elseif (preg_match('/youtube\.com\/embed\/([A-Za-z0-9_\-]{11})/', $rawUrl, $matches)) { $embedUrl = $rawUrl; } else { $embedUrl = null; // Invalid YouTube URL } } if ($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; } else { $embedUrl = null; // Invalid Vimeo URL } } @endphp @if ($embedUrl)