您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

table.blade.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. @props([
  2. 'data' => [
  3. [
  4. 'col1' => 1,
  5. 'col2' => 2,
  6. 'col3' => 3,
  7. ],
  8. ],
  9. 'showIndex' => false,
  10. ])
  11. @php
  12. // we derived the table heading based on each object key
  13. $columns = count($data) > 0 ? array_keys($data[0]) : [];
  14. @endphp
  15. <table class="w-full text-sm text-left text-gray-700 border-collapse">
  16. <thead class="bg-gray-100">
  17. <tr>
  18. @if ($showIndex)
  19. <th class="px-4 py-2 border">Bil</th>
  20. @endif
  21. @foreach ($columns as $column)
  22. <th class="px-4 py-2 border">{{ ucfirst(str_replace('_', ' ', $column)) }}</th>
  23. @endforeach
  24. </tr>
  25. </thead>
  26. <tbody>
  27. @foreach ($data as $index => $row)
  28. <tr>
  29. @if ($showIndex)
  30. <td class="px-4 py-2 border">{{ $index + 1 }}</td>
  31. @endif
  32. @foreach ($columns as $column)
  33. <td class="px-4 py-2 border">{{ $row[$column] }}</td>
  34. @endforeach
  35. </tr>
  36. @endforeach
  37. </tbody>
  38. </table>