@wilmer.lemke
To create a header table using a foreach loop in Laravel, you can follow these steps:
- Define the header array in your controller:
1
|
$headers = ['ID', 'Name', 'Email', 'Phone'];
|
- Pass the header array to your view:
1
|
return view('your-view', ['headers' => $headers]);
|
- In your view file, loop through the header array and display each header as a table header:
1
2
3
4
5
6
7
8
9
10
11
12
|
<table>
<thead>
<tr>
@foreach($headers as $header)
<th>{{ $header }}</th>
@endforeach
</tr>
</thead>
<tbody>
<!-- Add table rows here -->
</tbody>
</table>
|
- You can add table rows with data below the header section by fetching data from your database or any other source:
1
2
3
4
5
6
7
8
|
@foreach($data as $row)
<tr>
<td>{{ $row->id }}</td>
<td>{{ $row->name }}</td>
<td>{{ $row->email }}</td>
<td>{{ $row->phone }}</td>
</tr>
@endforeach
|
By following these steps, you can create a header table with foreach loop in Laravel.