@props([ 'name', // 필수: 슬롯 키 / 선택자 (예: logo, banner, og_image, thumbnail) 'label' => '이미지', // 라벨 텍스트 'model' => null, // Eloquent 모델 인스턴스 (수정 시: $shop, $program 등) 'width' => 60, // 미리보기 가로 크기(px) 'height' => 60, // 미리보기 세로 크기(px) 'ratioText' => '권장 비율: 1:1' // 가이드 텍스트 ]) @php $slotKey = $name; $inputId = "{$slotKey}_image_id"; $previewId = "{$slotKey}-preview"; $removeBtnId = "btn-remove-{$slotKey}"; // 1. 이미지 ID 추출 (old() 우선 -> 모델 가상 속성 get{Key}ImageIdAttribute 순) $currentImageId = old($inputId); if ($currentImageId === null && $model) { $method = \Illuminate\Support\Str::camel("{$slotKey}_image_id"); $currentImageId = $model->{$method} ?? null; } // 2. 미리보기 이미지 URL 추출 (M:N 다형성 피벗 우선 -> 구버전 레거시 경로 Fallback) $previewUrl = null; if ($model) { $slotImage = method_exists($model, 'getSlotImage') ? $model->getSlotImage($slotKey) : null; if ($slotImage) { $previewUrl = $slotImage->thumb_url ?: asset('storage/' . $slotImage->path); } else { $legacyColumn = "{$slotKey}_path"; if (!empty($model->{$legacyColumn})) { $previewUrl = asset('storage/' . $model->{$legacyColumn}); } } } @endphp