Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

evanzyl's avatar

Pagination in laravel

Good day

Is there anybody that can help me with adding pagination to laravel 5?

I inherited a site and not sure how to add it.

This is the function:

Route::get('/bookings', array( 'as' => 'private-bookings', function () {

  //show the page:
  $viewData = array(
                    'metaTitle'         => 'Bookings | ' . config('app.name'),
                    'metaSectionJs'     => 'private-bookings',
                    'metaSectionParent' => 'private-bookings',
                    'metaSectionUrl'    => '/bookings/',
                    'bookings'          => \Customerbooking\Booking::whereNull('deleted_at')
                                                        ->whereIn('status', array('draft', 'booked', 'paid', 'cancelled'))
                                                        ->orderBy('created_at', 'desc')
                                                        ->get()
                                                        
                   );
  
  return view('private.bookings.index', $viewData);

}

));

Do I add it here or on the blade?

Any assistance would be greatly appreciated.

Thank you.

0 likes
2 replies
sherwinmdev's avatar

@evanzyl instead of using ->get() use ->paginate(20) or the number or rows per page as the argument. in your blade, use $bookings->links() if that don't work, use $bookings->render(). can't remember which works in the older versions of laravel. that will display the page number links. then the loop that displays the records should have a limit per page based on the value passed in paginate().

evanzyl's avatar

Hi w1n78

Thank you so very much!!!!! I really appreciate your help!!!

Please or to participate in this conversation.