I want to display the serial number of each row of data on two tables, and I want the number to start from one on each table, like the table below
DJ List
| # | id | username | etc |
|---|----|-------------|------|
| 1 | 1 | john | ... |
| 2 | 2 | jane | ... |
User List
| # | id | username | etc |
|---|----|-------------|------|
| 1 | 3 | dave | ... |
| 2 | 4 | dick | ... |
but what I get is like in the table below
DJ List
| # | id | username | etc |
|---|----|-------------|------|
| 1 | 1 | john | ... |
| 2 | 2 | jane | ... |
User List
| # | id | username | etc |
|---|----|-------------|------|
| 3 | 3 | dave | ... |
| 4 | 4 | dick | ... |
here my code
manageUsers.blade.php
<div class="col s12">
<h5 class="light">DJ List</h5>
<table class="responsive-table">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Channel</th>
<th>Changed on</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach ($djs as $dj)
<tr>
<td>{{ $no++ }}</td>
<td>{{ $dj->id }}</td>
<td>{{ $dj->name }}</td>
<td>{{ $dj->email }}</td>
<td>{{ $dj->channel_name }}</td>
<td>{{ $dj->updated_at }}</td>
<td>
<a href="/users/{{ $dj->id }}/delete">delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<h5 class="light">User List</h5>
<table class="responsive-table">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Joined on</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr>
<td>{{ $no++ }}</td>
<td>{{ $user->id }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->created_at }}</td>
<td>
<a href="/user/{{ $user->id }}/delete">delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
UserController.php
public function index()
{
$djs = User::join('channels', 'users.id', '=', 'channels.user_id')
->select('users.*', 'channels.name as channel_name')
->where('type_id', '=', '2')
->orderBy('updated_at', 'desc')
->get();
$users = User::where('type_id', '=', '3')->orderBy('created_at', 'desc')->get();
return view('dashboard.manageUsers', compact('users', 'djs'))->with('no', 1);
}
can someone tell where my fault is, or help to tell a better way than this?