@php
$record = $getRecord();
$platform = $record->platform ?? 'youtube'; // fallback
$rawUrl = $record->embed_url ?? '';
$embedUrl = $rawUrl;
if ($platform === 'youtube') {
// Matches watch?v=, youtu.be/ and embed/ formats
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];
} else {
$embedUrl = null;
}
}
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;
}
}
@endphp
@if ($embedUrl)
@else
No preview
@endif