@props(['title' => 'Untitled', 'model' => null, 'headers' => [], 'data' => [], 'actions' => ''])

{{ $title }}

{{ $actions }}
@if (!is_null($model)) @foreach ($headers as $row) @php $label = $row['label'] ?? $row['key']; $field = $row['key']; $db_relation = $row['relation'] ?? null; if ($db_relation == null) { $relation_field = explode('.', $row['key']); if (count($relation_field) > 1) { $relation = $relation_field[0]; $field = $relation_field[1]; $model_field = $row['key']; } else { $field = $row['key']; $model_field = $row['key']; } } else { $relation_field = explode('.', $db_relation); $relation = $relation_field[0]; $field = $relation_field[1]; $model_field = $row['key']; } $value = null; // Check if the row type is 'document' or 'path' if (isset($row['type']) && in_array($row['type'], ['document', 'path'])) { $arr = explode('.', $row['key']); $json = json_decode($model->getMeta($arr[0]), true); $value = $json[$arr[1]] ?? null; } // Handle related model parsing elseif (str_contains($row['key'], '*')) { $parsed_key = explode('.', $row['key']); $related = $parsed_key[0]; $column_name = end($parsed_key); $value = $model->$related->pluck($column_name)->toArray(); } else { if (count($relation_field) > 1) { $value = $model->$relation->$field ?? $field; } else { $value = $model->{$row['key']}; } if (is_callable($value)) { $value = call_user_func($value, $model); } } @endphp {{ $label }} {{-- Handle 'document' or 'path' types --}} @if (isset($row['type']) && $row['type'] == 'path') @php $path = str_replace('/', '*', $value); @endphp @elseif (isset($row['type']) && $row['type'] == 'document') {{ $value }} {{-- Handle arrays --}} @elseif (is_array($value) && !empty($value)) @foreach ($value as $item) {{ $item }} @endforeach {{-- Handle non-empty or numeric values --}} @elseif (!empty($value) || is_numeric($value)) : {{ ucwords($value) }} {{-- Fallback for undefined values --}} @else : {{ __('-') }} @endif @endforeach @endif