Skip to content

Added pagination #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "kalnoy/nestedset",
"name": "sozidatel79/nestedset",
"description": "Nested Set Model for Laravel 4-5",
"keywords": ["laravel", "nested sets", "nsm", "database", "hierarchy"],
"license": "MIT",
Expand Down
24 changes: 24 additions & 0 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Support\Arr;
use LogicException;
use Illuminate\Database\Query\Expression;
use Illuminate\Pagination\Paginator;

class QueryBuilder extends Builder
{
Expand Down Expand Up @@ -1085,4 +1086,27 @@ public function root(array $columns = ['*'])
{
return $this->whereIsRoot()->first($columns);
}

/**
* @param null $perPage
* @param array $columns
* @param string $pageName
* @param null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Pagination\LengthAwarePaginator
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
$page = $page ?: Paginator::resolveCurrentPage($pageName);

$perPage = $perPage ?: $this->model->getPerPage();

$results = ($total = $this->toBase()->getCountForPagination())
? $this->forPage($page, $perPage)->get($columns)
: $this->model->newCollection();

return $this->paginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]);
}
}