@php // ✅ Collect possible file fields $fileItems = []; // 1) if model has attachments json if (isset($model->attachments) && !empty($model->attachments)) { $arr = is_array($model->attachments) ? $model->attachments : (json_decode($model->attachments, true) ?: []); foreach ($arr as $k => $v) { if (is_string($v) && $v) $fileItems[] = ['label' => is_string($k) ? $k : 'Attachment', 'path' => $v]; if (is_array($v) && isset($v['path'])) $fileItems[] = ['label' => $v['label'] ?? 'Attachment', 'path' => $v['path']]; } } // 2) scan columns that look like file paths if (method_exists($model, 'getAttributes')) { foreach ($model->getAttributes() as $key => $val) { if (!is_string($val) || empty($val)) continue; $k = strtolower($key); $looksLikeFileField = str_contains($k, 'file') || str_contains($k, 'path') || str_contains($k, 'attachment') || str_contains($k, 'document') || str_contains($k, 'doc') || str_contains($k, 'scan') || str_contains($k, 'photo') || str_contains($k, 'image') || str_contains($k, 'passport') || str_contains($k, 'tazkira') || str_contains($k, 'idcard') || str_contains($k, 'nid'); $looksLikePath = str_contains($val, '/') || str_contains($val, '\\') || str_contains($val, '.'); if ($looksLikeFileField && $looksLikePath) { $fileItems[] = ['label' => ucwords(str_replace(['_','-'],' ', $key)), 'path' => $val]; } } } // remove duplicates $fileItems = collect($fileItems) ->unique(fn($x) => $x['path']) ->values() ->all(); $fileUrl = function($path){ if (!$path) return null; // already url if (str_starts_with($path, 'http://') || str_starts_with($path, 'https://')) return $path; // try Storage try { return \Illuminate\Support\Facades\Storage::url($path); } catch (\Throwable $e) { // fallback return asset($path); } }; $isImage = function($path){ $p = strtolower($path ?? ''); return str_ends_with($p, '.jpg') || str_ends_with($p, '.jpeg') || str_ends_with($p, '.png') || str_ends_with($p, '.gif') || str_ends_with($p, '.webp') || str_ends_with($p, '.bmp') || str_ends_with($p, '.svg'); }; $isPdf = function($path){ return str_ends_with(strtolower($path ?? ''), '.pdf'); }; $isWord = function($path){ $p = strtolower($path ?? ''); return str_ends_with($p, '.doc') || str_ends_with($p, '.docx'); }; $isExcel = function($path){ $p = strtolower($path ?? ''); return str_ends_with($p, '.xls') || str_ends_with($p, '.xlsx') || str_ends_with($p, '.csv'); }; $baseName = function($path){ $p = str_replace('\\','/',$path ?? ''); return basename($p); }; $getFileIcon = function($path) use ($isImage, $isPdf, $isWord, $isExcel) { if ($isImage($path)) return 'far fa-image text-primary'; if ($isPdf($path)) return 'far fa-file-pdf text-danger'; if ($isWord($path)) return 'far fa-file-word text-primary'; if ($isExcel($path)) return 'far fa-file-excel text-success'; return 'far fa-file text-secondary'; }; $getFileColor = function($path) use ($isImage, $isPdf, $isWord, $isExcel) { if ($isImage($path)) return 'bg-primary bg-opacity-10'; if ($isPdf($path)) return 'bg-danger bg-opacity-10'; if ($isWord($path)) return 'bg-primary bg-opacity-10'; if ($isExcel($path)) return 'bg-success bg-opacity-10'; return 'bg-secondary bg-opacity-10'; }; @endphp @if(count($fileItems))
{{ $name }}
{{ $name }}