fix
This commit is contained in:
parent
caea0f2873
commit
763e571cf6
@ -75,38 +75,90 @@
|
||||
</h3>
|
||||
|
||||
@if($pelanggan->form && count($pelanggan->form) > 0)
|
||||
@php
|
||||
$fotoFields = [];
|
||||
$textFields = [];
|
||||
|
||||
foreach ($pelanggan->form as $field => $value) {
|
||||
$isFoto = false;
|
||||
|
||||
if (is_array($value)) {
|
||||
// jika array berisi gambar
|
||||
$isFoto = collect($value)->contains(function ($v) {
|
||||
return preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $v)
|
||||
|| Str::startsWith($v, ['storage/', 'photos/', 'uploads/', 'images/']);
|
||||
});
|
||||
} elseif (is_string($value)) {
|
||||
// jika satu gambar
|
||||
$isFoto = preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $value)
|
||||
|| Str::startsWith($value, ['storage/', 'photos/', 'uploads/', 'images/']);
|
||||
}
|
||||
|
||||
if ($isFoto) {
|
||||
$fotoFields[$field] = $value;
|
||||
} else {
|
||||
$textFields[$field] = $value;
|
||||
}
|
||||
}
|
||||
$orderedFields = array_merge($textFields, $fotoFields);
|
||||
@endphp
|
||||
|
||||
<div class="overflow-hidden rounded-lg border border-gray-200">
|
||||
<table class="min-w-full text-sm text-gray-700">
|
||||
<tbody class="divide-y divide-gray-200">
|
||||
@foreach($pelanggan->form as $field => $value)
|
||||
@foreach($orderedFields as $field => $value)
|
||||
<tr class="hover:bg-gray-50 align-top">
|
||||
<th class="px-4 py-3 font-semibold bg-gray-50 w-1/4">
|
||||
{{ ucwords(str_replace('_', ' ', $field)) }}
|
||||
</th>
|
||||
<td class="px-4 py-3">
|
||||
{{-- ✅ Jika value adalah array (banyak foto) --}}
|
||||
@if(is_array($value))
|
||||
{{ implode(', ', $value) }}
|
||||
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3">
|
||||
@foreach($value as $img)
|
||||
@php
|
||||
if (Str::startsWith($img, ['http://', 'https://'])) {
|
||||
$imageUrl = $img;
|
||||
} elseif (Str::startsWith($img, ['storage/', 'public/'])) {
|
||||
$imageUrl = asset($img);
|
||||
} elseif (Str::startsWith($img, 'photos/')) {
|
||||
$imageUrl = asset('storage/' . $img);
|
||||
} else {
|
||||
$imageUrl = asset('storage/' . $img);
|
||||
}
|
||||
@endphp
|
||||
<a href="{{ $imageUrl }}" target="_blank">
|
||||
<img src="{{ $imageUrl }}"
|
||||
alt="{{ $field }}"
|
||||
class="w-32 h-32 object-cover rounded-lg border border-gray-200 shadow-sm hover:shadow-md transition">
|
||||
</a>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
{{-- ✅ Jika value adalah path atau URL gambar --}}
|
||||
{{-- ✅ Jika gambar tunggal --}}
|
||||
@elseif(
|
||||
is_string($value) &&
|
||||
(preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $value)
|
||||
|| Str::startsWith($value, ['storage/', 'uploads/', 'images/']))
|
||||
|| Str::startsWith($value, ['storage/', 'uploads/', 'images/', 'photos/']))
|
||||
)
|
||||
@php
|
||||
// Cek apakah gambar disimpan di storage Laravel
|
||||
$imageUrl = Str::startsWith($value, ['http://', 'https://'])
|
||||
? $value
|
||||
: asset($value);
|
||||
if (Str::startsWith($value, ['http://', 'https://'])) {
|
||||
$imageUrl = $value;
|
||||
} elseif (Str::startsWith($value, ['storage/', 'public/'])) {
|
||||
$imageUrl = asset($value);
|
||||
} elseif (Str::startsWith($value, 'photos/')) {
|
||||
$imageUrl = asset('storage/' . $value);
|
||||
} else {
|
||||
$imageUrl = asset('storage/' . $value);
|
||||
}
|
||||
@endphp
|
||||
|
||||
<a href="{{ $imageUrl }}" target="_blank" class="block mt-2">
|
||||
<img src="{{ $imageUrl }}"
|
||||
alt="{{ $field }}"
|
||||
class="w-40 h-40 object-cover rounded-lg border border-gray-200 shadow-sm hover:shadow-md transition">
|
||||
</a>
|
||||
|
||||
{{-- ✅ Jika value adalah URL biasa --}}
|
||||
{{-- ✅ Jika URL biasa --}}
|
||||
@elseif(is_string($value) && filter_var($value, FILTER_VALIDATE_URL))
|
||||
<a href="{{ $value }}" target="_blank"
|
||||
class="text-blue-600 hover:text-blue-800 underline break-words">
|
||||
@ -127,6 +179,5 @@
|
||||
<p class="text-gray-500 italic mt-4">Tidak ada data form tambahan.</p>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
Loading…
Reference in New Issue
Block a user