@props([ 'src' => '', 'alt' => '', 'class' => '', 'style' => '', 'width' => null, 'height' => null, 'fallback' => "data:image/svg+xml;utf8,No Image", ]) @php $val = trim((string) $src); $isAbsolute = str_starts_with($val, 'http://') || str_starts_with($val, 'https://') || str_starts_with($val, '//'); $isStoragePrefix = str_starts_with($val, '/storage') || str_starts_with($val, 'storage/'); $isPublicPrefix = str_starts_with($val, '/public/') || str_starts_with($val, 'public/'); if ($val === '') { $url = $fallback; } elseif ($isAbsolute) { $url = $val; } elseif ($isStoragePrefix) { // Normalize variants like /storage/public/... to /storage/... $normalized = ltrim($val, '/'); $normalized = str_replace('storage/public/', 'storage/', $normalized); $url = asset($normalized); } elseif ($isPublicPrefix) { // Files stored as public/... should be referenced through storage symlink $normalized = 'storage/' . ltrim(str_replace(['public/', '/public/'], '', $val), '/'); $url = asset($normalized); } else { // Treat as relative to public root (e.g., assets/img/... or logos/..) // If looks like an uploaded path (no storage/ prefix), prefer storage/ $maybeUpload = preg_match('#^(logos|images|uploads|photos|pictures)/#i', $val) === 1; $url = $maybeUpload ? asset('storage/' . ltrim($val, '/')) : asset(ltrim($val, '/')); } $attrs = []; if ($width) $attrs[] = 'width="'.e($width).'"'; if ($height) $attrs[] = 'height="'.e($height).'"'; if ($class) $attrs[] = 'class="'.e($class).'"'; if ($style) $attrs[] = 'style="'.e($style).'"'; $attrStr = $attrs ? ' '.implode(' ', $attrs) : ''; @endphp {{ $alt }}