Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel show All Users in Table list / Display Correct

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

like image 864
anitakarst33 Avatar asked Jan 27 '26 12:01

anitakarst33


1 Answers

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>
like image 101
Lloople Avatar answered Jan 29 '26 12:01

Lloople



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!