Created
May 13, 2019 07:45
-
-
Save CharlieEtienne/74935daa02c934bac46967984a12fe8e to your computer and use it in GitHub Desktop.
This allows you to call ->paginate() on an Eloquent Collection
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 | |
use Illuminate\Database\Eloquent\Collection; | |
// Register in 'boot()' method in app/Providers/AppServiceProvider.php | |
// This allows you to call ->paginate() on an Eloquent Collection | |
Collection::macro('paginate', function ($perPage = 10, $current_page = null, $options = []) { | |
$current_page = $current_page ?: (Paginator::resolveCurrentPage() ?: 1); | |
return (new LengthAwarePaginator($this->forPage($current_page, $perPage)->values()->all(), $this->count(), $perPage, $current_page, $options))->withPath(''); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment