calicastle's avatar

Pagination Not Working

When I'm testing my application in local environment, the pagination worked. But once I deployed it up to the server, and I visited it with ?page=2, it didn't skip the first page, instead the list result is still the first page's. I died and dumped the $users variable and it seems like it got stuck on page 1, but the lastPage is 2 and I just can't visit page 2 for whatever reason it might be.

I suspected that there's something wrong with my server php environment, but I can't find any close answer similar to mine.

Server PHP: PHP 5.6.9

Local PHP: PHP 7.0.3

This is the code in my Controller:

    public function showCooperatives()
    {
        $users = User::cooperatives()->hot()->paginate();

        return view('users.cooperatives', compact("users"));
    }

In my User Eloquent Model, I declared the number of items per page:

protected $perPage = 35;

and in the view:

<nav class="home-pagination">
         {!! $users->links() !!}
 </nav>
0 likes
3 replies
Jaytee's avatar

Pass the $perPage variable into the paginate() method.

 $users = User::cooperatives()->hot()->paginate($perPage);
// OR;

$users = User::cooperatives()->hot()->paginate(35);

Please or to participate in this conversation.