bestmomo's avatar

[5.3] Pagination

There is something weird with Laravel 5.3 pagination :

  • There is always the pagination even if we dont exceed the pagination number.
  • Worst : say we have 4 records and you paginate on 3, the pagination is ok on first page but doesn't appears on second one. What do you think ? Looks like a bug...
0 likes
9 replies
minjon's avatar

@bestmomo I have no problem with pagination, it's running smoothly with me. Will you provide your code?

bestmomo's avatar

@minjon

With a fresh Laravel 5.3, with users table with 4 records :

// Route
Route::get('/', function () {
    $users = \App\User::paginate(4);
    return view('welcome', compact('users'));
});

// View
@foreach($users as $user)
    <li>{{ $user->name }}</li>
@endforeach
{!! $users->links() !!}

I get the pagination with only page 1 !

And with a paginate(3) I get the page 2 without pagination.

minjon's avatar

@bestmomo Looking at the code above, if you have a users table with 4 records and set User::paginate(4) you should get only one page, i.e. page 1.:) But, I copied your code into my project where I already had a users table with 5 records and pagination set to 5, which was fine.

However, a big surprise came to me when I set paginate(4), and there was 1 record, but no pagination links on the second page. The same happened with paginate(2). I got 3 pages, the first two with 2 records each and pagination links, but the last one with 1 record and no links. However, when I set paginate(3) the second page had links, but it had more than 1 record either (i.e. 2).

In other words, it seems that if total # of records % records per page = 1, there are no pagination links on the last page and there is no way of moving across the pages other than changing page= $value in the browser.

I allow that I am not right, so it would nice to hear what others have to say ...

bestmomo's avatar

@minjon

Looking at the code above, if you have a users table with 4 records and set User::paginate(4) you should get only one page, i.e. page 1.:) But, I copied your code into my project where I already had a users table with 5 records and pagination set to 5, which was fine.

You mean you dont have the pagination with only page 1 ?

minjon's avatar

@bestmomo Aha, I see what you mean. In addition to the above mentioned, yes, I do have the pagination link with only page 1, which is strange.

Btw, I reviewed my code in Lar 5.2 and pagination worked properly - no pagination links on page 1, and always yes on the last page.

davorminchorov's avatar

I've noticed that after the upgrade to 5.3, I always have pagination links (1 in this case) even with less records than the number of records specified. At first I thought it was because of the search I implemented, but it doesn't seem like it is causing it.

JL8720's avatar

@bestmomo I updated composer but still have the same problem. My files at vendor/laravel/framework/src/Illuminate/Pagination/resources/views are updated to the version of the commit. What else can I do?

Please or to participate in this conversation.