Created
June 29, 2017 21:17
-
-
Save fearrr/b7a9c369d93c2e7040487b962a866a52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param $items //Принимает коллекцию или массив | |
* @param $page //Принимает $request->page | |
* @param $perPage //Принимает кол-во элементов на странице | |
* @param $url //Принимает $request->url() | |
* @param $query //Принимает $request->query() | |
* @return LengthAwarePaginator //Возвращает объект Paginator | |
*/ | |
public function paginate($items, $page = null, $perPage = 15, $url, $query){ | |
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1); | |
$items = $items instanceof Collection ? $items : Collection::make($items); | |
return new LengthAwarePaginator( | |
$items->forPage($page, $perPage), | |
$items->count(), // Элементов всего | |
$perPage, // Элементов на страницу | |
$page, // Текущая страница | |
[ | |
'path' => $url, | |
'query' => $query | |
] // Параметры текущего запроса | |
); | |
} | |
//Пример вызова | |
$items_paginate = $this->paginate($items, $request->page, 30, $request->url(), $request->query()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment