@php $url = $block->content['url'] ?? ''; $caption = $block->content['caption'] ?? ''; $title = e($block->content['title'] ?? 'Video'); $allowedEmbedHosts = ['www.youtube.com', 'youtube.com', 'youtu.be', 'www.vimeo.com', 'vimeo.com', 'player.vimeo.com']; $parsed = parse_url($url); $host = strtolower($parsed['host'] ?? ''); $isEmbed = in_array($host, $allowedEmbedHosts, true); // Normalise YouTube watch URLs to embed URLs if (in_array($host, ['www.youtube.com', 'youtube.com'], true) && str_contains($url, '/watch')) { parse_str($parsed['query'] ?? '', $qs); if (!empty($qs['v'])) { $url = 'https://www.youtube.com/embed/' . rawurlencode($qs['v']); } } elseif ($host === 'youtu.be') { $videoId = ltrim($parsed['path'] ?? '', '/'); $url = 'https://www.youtube.com/embed/' . rawurlencode($videoId); } elseif (in_array($host, ['www.vimeo.com', 'vimeo.com'], true)) { $videoId = ltrim($parsed['path'] ?? '', '/'); $url = 'https://player.vimeo.com/video/' . rawurlencode($videoId); } @endphp
@if($isEmbed)
@elseif($url) @endif @if($caption)
{{ $caption }}
@endif