From cb68bc9df39af60f2d7256b18417bc108bc0e6dc Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 21 Jul 2018 17:47:33 +0300 Subject: [PATCH 1/6] Update QueryBuilder.php --- src/QueryBuilder.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index b406c48..87e99ba 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -11,6 +11,7 @@ use Illuminate\Support\Arr; use LogicException; use Illuminate\Database\Query\Expression; +use Illuminate\Pagination\Paginator; class QueryBuilder extends Builder { @@ -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, + ]); + } } From 6d7339a321299ddbebec5714b6c149472960506e Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 21 Jul 2018 17:49:30 +0300 Subject: [PATCH 2/6] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ca3d6c6..682d159 100644 --- a/composer.json +++ b/composer.json @@ -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", From 7ee9ddbc85350817edb5b6dbc55fbd8fb2eb6652 Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 21 Jul 2018 17:53:16 +0300 Subject: [PATCH 3/6] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 682d159..ca3d6c6 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sozidatel79/nestedset", + "name": "kalnoy/nestedset", "description": "Nested Set Model for Laravel 4-5", "keywords": ["laravel", "nested sets", "nsm", "database", "hierarchy"], "license": "MIT", From c5102e0d3974523108eba34997b98833af06a639 Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 28 Jul 2018 01:44:54 +0300 Subject: [PATCH 4/6] Added Pagination --- src/QueryBuilder.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 87e99ba..66aab6c 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -1109,4 +1109,24 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', 'pageName' => $pageName, ]); } + + /** + * @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, + ]); + } } From 62a1190b4effa7588de8b44e0205129db11f5e0f Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 28 Jul 2018 01:45:45 +0300 Subject: [PATCH 5/6] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ca3d6c6..682d159 100644 --- a/composer.json +++ b/composer.json @@ -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", From e7033a76481baa342dd3b130827746430dc46efc Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 28 Jul 2018 02:31:49 +0300 Subject: [PATCH 6/6] Update QueryBuilder.php --- src/QueryBuilder.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 66aab6c..87e99ba 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -1109,24 +1109,4 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', 'pageName' => $pageName, ]); } - - /** - * @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, - ]); - } }