Reputation: 33
I want List all my Users in an Table, per line one Username.
But i get only the first User in this Table , all other Users are side by side.
My Blade:
<table class="table table-hover">
<thead>
<th>Username</th>
<th>Orders</th>
<th>Balance</th>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{$user->username}} </td>
<td>{{$user->purchases}} </td>
<td>{{$user->balance}} </td>
</tr>
</tbody>
</table>
Controller:
public function ShowUserlist(){
$users = User::all();
return view('profile.dashboard', compact('users'));
}
The First User from my DB is in the <table class="table table-hover">
the other ones looks like: testtesttesttesttesttesttesttest
under the Table.
How can i sort it per User one Line?
Thanks
Upvotes: 3
Views: 11929
Reputation: 1844
You need to close the @foreach after each tr
tag
<table class="table table-hover">
<thead>
<th>Username</th>
<th>Orders</th>
<th>Balance</th>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{$user->username}} </td>
<td>{{$user->purchases}} </td>
<td>{{$user->balance}} </td>
</tr>
@endforeach
</tbody>
</table>
Upvotes: 2
Reputation: 795
You forgot to close foreach
<table class="table table-hover">
<thead>
<th>Username</th>
<th>Orders</th>
<th>Balance</th>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{$user->username}} </td>
<td>{{$user->purchases}} </td>
<td>{{$user->balance}} </td>
</tr>
@endforeach
</tbody>
</table>
Upvotes: 0
Reputation: 9853
<table class="table table-hover">
<thead>
<tr>
<th>Username</th>
<th>Orders</th>
<th>Balance</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{$user->username}} </td>
<td>{{$user->purchases}} </td>
<td>{{$user->balance}} </td>
</tr>
@endforeach
</tbody>
</table>
Upvotes: 0