Use macro for pagination links
This commit is contained in:
parent
eb4f479b97
commit
debbfa98d6
6 changed files with 46 additions and 28 deletions
|
@ -6,6 +6,8 @@ use App\Models\Note;
|
|||
use App\Observers\NoteObserver;
|
||||
use Codebird\Codebird;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Dusk\DuskServiceProvider;
|
||||
|
@ -47,6 +49,30 @@ class AppServiceProvider extends ServiceProvider
|
|||
|
||||
return $cb;
|
||||
});
|
||||
|
||||
/**
|
||||
* Paginate a standard Laravel Collection.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param int $total
|
||||
* @param int $page
|
||||
* @param string $pageName
|
||||
* @return array
|
||||
*/
|
||||
Collection::macro('paginate', function ($perPage, $total = null, $page = null, $pageName = 'page') {
|
||||
$page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
|
||||
|
||||
return new LengthAwarePaginator(
|
||||
$this->forPage($page, $perPage),
|
||||
$total ?: $this->count(),
|
||||
$perPage,
|
||||
$page,
|
||||
[
|
||||
'path' => LengthAwarePaginator::resolveCurrentPath(),
|
||||
'pageName' => $pageName,
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue