Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 - Manual pagination

Pagination::make() method doesn't exist in Pagination class anymore in Laravel 5.

Is there a workaround to make manual pagination work in Laravel 5?

like image 825
aBhijit Avatar asked Nov 30 '14 12:11

aBhijit


People also ask

How can I get pagination in Laravel?

There are several ways to paginate items. The simplest is by using the paginate method on the query builder or an Eloquent query. The paginate method provided by Laravel automatically takes care of setting the proper limit and offset based on the current page being viewed by the user.

How does Laravel pagination work?

Pagination works by selecting a specific chunk of results from the database to display to the user. The total number of results is calculated and then split between pages depending on how many results you want to return on a page.


1 Answers

You need to add use:

use Illuminate\Pagination\LengthAwarePaginator as Paginator;

and now you can use:

 $paginator = new Paginator($items, $count, $limit, $page, [
            'path'  => $this->request->url(),
            'query' => $this->request->query(),
        ]);

to get data in the same format as paginating on model object;

like image 141
Marcin Nabiałek Avatar answered Oct 09 '22 15:10

Marcin Nabiałek