Skip to content

Commit 060bd8f

Browse files
authored
Merge pull request #413 from stevenmaguire/sm-add-support-for-container-resolved-paginator
Update builder class pagination methods to resolve LengthAwarePaginator using container
2 parents 9880e9c + 3d0d4fc commit 060bd8f

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/Builder.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravel\Scout;
44

5+
use Illuminate\Container\Container;
56
use Illuminate\Pagination\LengthAwarePaginator;
67
use Illuminate\Pagination\Paginator;
78
use Illuminate\Support\Traits\Macroable;
@@ -270,10 +271,16 @@ public function paginate($perPage = null, $pageName = 'page', $page = null)
270271
$this, $rawResults = $engine->paginate($this, $perPage, $page), $this->model
271272
)->all());
272273

273-
$paginator = (new LengthAwarePaginator($results, $engine->getTotalCount($rawResults), $perPage, $page, [
274-
'path' => Paginator::resolveCurrentPath(),
275-
'pageName' => $pageName,
276-
]));
274+
$paginator = Container::getInstance()->makeWith(LengthAwarePaginator::class, [
275+
'items' => $results,
276+
'total' => $engine->getTotalCount($rawResults),
277+
'perPage' => $perPage,
278+
'currentPage' => $page,
279+
'options' => [
280+
'path' => Paginator::resolveCurrentPath(),
281+
'pageName' => $pageName,
282+
],
283+
]);
277284

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

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

299-
$paginator = (new LengthAwarePaginator($results, $engine->getTotalCount($results), $perPage, $page, [
300-
'path' => Paginator::resolveCurrentPath(),
301-
'pageName' => $pageName,
302-
]));
306+
$paginator = Container::getInstance()->makeWith(LengthAwarePaginator::class, [
307+
'items' => $results,
308+
'total' => $engine->getTotalCount($results),
309+
'perPage' => $perPage,
310+
'currentPage' => $page,
311+
'options' => [
312+
'path' => Paginator::resolveCurrentPath(),
313+
'pageName' => $pageName,
314+
],
315+
]);
303316

304317
return $paginator->appends('query', $this->query);
305318
}

0 commit comments

Comments
 (0)