@php $platform = $platform ?? 'youtube'; $rawUrl = $url ?? ''; $embedUrl = null; if ($platform === 'youtube') { if (preg_match('/(?:youtu\.be\/|youtube\.com\/(?:watch\?v=|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 @if ($embedUrl)