what if you use the standard method of creating the links? {{ $users->links() }}
Oct 27, 2017
3
Level 10
Pagination keep looping with the same results - Laravel 5.5
Hello,
I wonder if anyone had the same problem please.
I only have 15 results in my db and the pagination numbers are showing from 1 to 137 pages. When I click on a number, it shows the same results again and again.
here is my code
public function index()
{
$users = DB::table('users')
->join('roles', 'roles.id', '=', 'users.role_id')
->join('towns', 'towns.id', '=', 'towns.id')
->select('users.*', 'roles.name AS role_name', 'towns.town')
->paginate(15);
return view('admin.users-view', ['users' => $users]);
}
<tbody>
@foreach ($users as $user)
<tr>
<td class="col-md-1">{{ $user->id }}</td>
<td class="col-md-1">{{ $user->username }}</td>
<td class="col-md-1">{{ $user->name }}</td>
<td class="col-md-1">{{ $user->surname }}</td>
<td class="col-md-2">{{ $user->email }}</td>
<td class="col-md-2">{{ $user->town }}</td>
@if($user->isactivated == 1)
<td class="col-md-1"><button class="btn btn-success" type="submit">Activated</button></td>
@else
<td class="col-md-1"><button class="btn btn-danger" type="submit">Not Activated</button></td>
@endif
<td class="col-md-1">{{ $user->role_name }}</td>
<td class="col-md-1"><a href="{{ action('Admin\UserController@edit', $user->id) }}" class="btn btn-warning" type="submit">Edit</a></td>
<td class="col-md-1">
<form action="{{ action('Admin\UserController@destroy', $user->id) }}" method="post">
{{csrf_field()}}
<input name="_method" type="hidden" value="DELETE">
<button class="btn btn-danger" type="submit" onclick="var result = confirm('Do you really want to delete this user?')">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="container">
<nav aria-label="Page navigation">
<ul class="pagination">
<?php echo $users->appends(['sort' => 'users'])->render(); ?>
</ul>
</nav>
</div>
Thank you for your help.
Please or to participate in this conversation.