to paginate collection
*
* @param Request $data
* @param $products
* @param int $perPage
* @return LengthAwarePaginator
*/
public static function make(Request $data, $products, $perPage = 15, $selector = 0, $category = 0)
{
$perPage = $perPage ?? 15;
$currentPage = LengthAwarePaginator::resolveCurrentPage();
$itemCollection = collect($products);
$currentPageItems = $itemCollection->slice(($currentPage * $perPage) - $perPage, $perPage)->all();
$products = new LengthAwarePaginator($currentPageItems , count($itemCollection), $perPage, ['selector' => $selector, 'category' => $category]);
$products->setPath($data->url());
return $products;
}
}
ebat
Обсуждают сегодня