Skip to content

Commit

Permalink
Merge pull request #413 from stevenmaguire/sm-add-support-for-contain…
Browse files Browse the repository at this point in the history
…er-resolved-paginator

Update builder class pagination methods to resolve LengthAwarePaginator using container
  • Loading branch information
taylorotwell authored Aug 19, 2020
2 parents 9880e9c + 3d0d4fc commit 060bd8f
Showing 1 changed file with 21 additions and 8 deletions.
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

0 comments on commit 060bd8f

Please sign in to comment.