Support the ongoing development of Laravel.io →
posted 5 years ago
Last updated 1 year ago.
0

Hi,

First of all you should update your "query":

$pubs = \App\Pub::where('rsTown', 'Brighton')
               ->orderBy('id', 'desc')
               ->paginate(10); // the number of the items per page
return view('pubindex',compact('pubs'));

In the view you can generate the links of the pages:

{{ $pubs->links() }}

That is all. Laravel do the other stuffs. But the Laravel has a really good documentation about this: https://laravel.com/docs/5.6/pagination

0

Hi, Hopfully that's gonna work :

public function index()
{
     // All you need to make the pagination works, 
     // is to replace get() with paginate(10)
     $pubs=\App\Pub::all();
     $pubs=\App\Pub::where('rsTown', 'Brighton')
            ->orderBy('id', 'desc')
            ->paginate(10);
     return view('pubindex',compact('pubs'));
}

in the view: put

{{ $pubs->links() }}
0

Excellent! Thank you!

Where I was going wrong originally was, I was keeping in get();

0

You Welcome

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.