Jishad P Jishad P - 5 months ago 51
PHP Question

Laravel Manual Pagination Error

I have a issue related to Laravel5 Manual Pagination.
I need to process an array of query builder result and some other arrays and make a pagination for that.

controller.

public function searchCategory($id){
$arr = DB::table('business_businesscatagories')->lists('fk_business_id');
return Paginator::make($arr, count($arr), 2);
}


Namespaces..

use Illuminate\Pagination\LengthAwarePaginator as Paginator;


But I got the error like below..

FatalErrorException in IndexController.php line 122:
Call to undefined method Illuminate\Pagination\LengthAwarePaginator::make()


How can I solve this issue....

Answer

I examined Illuminate\Pagination\LengthAwarePaginator and was able to confirm that it doesn't have make method.

However you can achieve this by using its constructor method.

__construct(mixed $items, int $perPage, int|null $currentPage = null, array $options = array())

Since you already have the correct namespace specified:

use Illuminate\Pagination\LengthAwarePaginator as Paginator;

You could simply do this:

$paginator = new Paginator($items, $total, $per_page);

Comments