Skip to content
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

Update builder class pagination methods to resolve LengthAwarePaginator using container #413

Merged
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
29 changes: 21 additions & 8 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Scout;

use Illuminate\Container\Container;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Traits\Macroable;
Expand Down Expand Up @@ -270,10 +271,16 @@ public function paginate($perPage = null, $pageName = 'page', $page = null)
$this, $rawResults = $engine->paginate($this, $perPage, $page), $this->model
)->all());

$paginator = (new LengthAwarePaginator($results, $engine->getTotalCount($rawResults), $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]));
$paginator = Container::getInstance()->makeWith(LengthAwarePaginator::class, [
'items' => $results,
'total' => $engine->getTotalCount($rawResults),
'perPage' => $perPage,
'currentPage' => $page,
'options' => [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
],
]);

return $paginator->appends('query', $this->query);
}
Expand All @@ -296,10 +303,16 @@ public function paginateRaw($perPage = null, $pageName = 'page', $page = null)

$results = $engine->paginate($this, $perPage, $page);

$paginator = (new LengthAwarePaginator($results, $engine->getTotalCount($results), $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]));
$paginator = Container::getInstance()->makeWith(LengthAwarePaginator::class, [
'items' => $results,
'total' => $engine->getTotalCount($results),
'perPage' => $perPage,
'currentPage' => $page,
'options' => [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
],
]);

return $paginator->appends('query', $this->query);
}
Expand Down