Last active
August 9, 2021 18:22
-
-
Save azimidev/0c1a4ff1b95d5195c82f1da526425c1e to your computer and use it in GitHub Desktop.
Laravel Custom Paginate
This file contains 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 $perPage | |
* @return \Illuminate\Pagination\LengthAwarePaginator | |
*/ | |
function custom_paginate($items, $perPage) | |
{ | |
$pageStart = request('page', 1); | |
$offSet = ($pageStart * $perPage) - $perPage; | |
// $itemsForCurrentPage = array_slice($items, $offSet, $perPage, TRUE); | |
$itemsForCurrentPage = $items->slice($offSet, $perPage); | |
return new Illuminate\Pagination\LengthAwarePaginator( | |
$itemsForCurrentPage, $items->count(), $perPage, | |
Illuminate\Pagination\Paginator::resolveCurrentPage(), | |
['path' => Illuminate\Pagination\Paginator::resolveCurrentPath()] | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried a lot of paging and there are bugs, this is normal. Good job.