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
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() }}
Excellent! Thank you!
Where I was going wrong originally was, I was keeping in get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community