dimanche 10 février 2019

Laravel 5.7 pagination showing but not returning the correct data when changing page

Here is my route:

Route::namespace('Admin')->prefix('admin')->name('admin.')->middleware(['auth', 'auth.admin'])->group(function () {

Route::prefix('users')->group(function() {
    Route::get('/', 'UserController@index')->name('user');

In my controller I have the following:

$users = User::with('roles', 'group')->paginate(1);

return view('admin.user.index')->with(['users' => $users]);

Without the pagination, this works fine and returns the 4 results I have. with the pagination the UI part of things work, it displays me 4 links in the pagination controls (1 result per page) but when clicking the link to page 2, 3 and 4 it just returns the same first item every time.

I can see it's passing the URL param in the network tab for example:

http://localhost:8050/admin/users?page=2

However it has no effect on the result returned so I assume the issue is with my Eloquent query?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire