Created
May 10, 2018 08:33
-
-
Save kundancool/ef7ed2165ea5c57d87e499f1d328cb5f to your computer and use it in GitHub Desktop.
Laravel Length Aware Pagination for custom array
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 | |
public function sampleArrayPaginator(Request $request) { | |
$response = array(); | |
$page = ($request->has('page')) ? intval($request->page) : 1; | |
$size = ($request->has('size')) ? intval($request->size) : 10; | |
$collection = collect($response); | |
$total = $collection->count(); | |
return new LengthAwarePaginator( | |
array_values($collection->forPage($page, $size)->toArray()), | |
$collection->count(), | |
$size, | |
$page | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment