@props([ 'data' => [ [ 'col1' => 1, 'col2' => 2, 'col3' => 3, ], ], 'showIndex' => false, ]) @php // we derived the table heading based on each object key $columns = count($data) > 0 ? array_keys($data[0]) : []; @endphp @if ($showIndex) @endif @foreach ($columns as $column) @endforeach @foreach ($data as $index => $row) @if ($showIndex) @endif @foreach ($columns as $column) @endforeach @endforeach
Bil{{ ucfirst(str_replace('_', ' ', $column)) }}
{{ $index + 1 }}{{ $row[$column] }}