@php $items = []; foreach ($media as $m) { $raw = trim($m->path ?? ''); $url = null; if ($raw !== '') { if (preg_match('~^https?://~i', $raw)) { $url = $raw; } elseif (str_starts_with($raw,'public/storage/')) { $p = substr($raw,7); if (file_exists(public_path($p))) $url = asset($p); } elseif (str_starts_with($raw,'storage/')) { if (file_exists(public_path($raw))) $url = asset($raw); } else { if (\Storage::disk('public')->exists($raw)) { $url = \Storage::url($raw); } elseif (file_exists(public_path($raw))) { $url = asset($raw); } } } // Solo agregamos a $items si tenemos URL real if ($url) { $items[] = [ 'id'=>$m->id, 'url'=>$url, 'is_primary'=>(bool)$m->is_primary ]; } } // Si no hay items, ponemos uno solo de placeholder (opcional) if (empty($items)) { $items[] = [ 'id'=>0, 'url'=>asset('img/placeholder_zapato_detalle.svg'), 'is_primary'=>true ]; } @endphp