Compare commits

..

No commits in common. "2d4657067a43ea44a682707481ec0c0cdf246883" and "6f96b18126b6b6e1add9e8d2bf538ec9a80e8461" have entirely different histories.

View File

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