Last active
August 6, 2018 22:23
-
-
Save ahkmunna/210e5cd19c72942b8520f65a879447bd to your computer and use it in GitHub Desktop.
Add pagination functionality on Laravel collections. Add this macro in the boot method in AppServiceProvider
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
// Add pagination on collections | |
if (!Collection::hasMacro('paginate')) { | |
Collection::macro('paginate', | |
function ($perPage = 15, $page = null, $options = []) | |
{ | |
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1); | |
return (new LengthAwarePaginator( | |
$this->forPage($page, $perPage), $this->count(), $perPage, $page, $options)) | |
->withPath(url()->full()); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment