mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
fixed #298
This commit is contained in:
parent
046a05c088
commit
e79f3acc00
@ -5,6 +5,7 @@ use Illuminate\Container\Container;
|
|||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Pagination\Paginator;
|
use Illuminate\Pagination\Paginator;
|
||||||
use Laravel\Scout\Contracts\PaginatesEloquentModels;
|
use Laravel\Scout\Contracts\PaginatesEloquentModels;
|
||||||
|
use Typesense\LaravelTypesense\Engines\TypesenseEngine;
|
||||||
|
|
||||||
/** @mixin \Laravel\Scout\Builder */
|
/** @mixin \Laravel\Scout\Builder */
|
||||||
class ScoutBuilderMixin
|
class ScoutBuilderMixin
|
||||||
@ -18,6 +19,7 @@ class ScoutBuilderMixin
|
|||||||
{
|
{
|
||||||
return function (int|null $perPage = null, string $pageName = 'page', int|null $page = null) {
|
return function (int|null $perPage = null, string $pageName = 'page', int|null $page = null) {
|
||||||
/** @var \Laravel\Scout\Builder $this */
|
/** @var \Laravel\Scout\Builder $this */
|
||||||
|
/** @var TypesenseEngine $engine */
|
||||||
$engine = $this->engine();
|
$engine = $this->engine();
|
||||||
if ($engine instanceof PaginatesEloquentModels) {
|
if ($engine instanceof PaginatesEloquentModels) {
|
||||||
return $engine->paginate($this, $perPage, $page)->appends('query', $this->query);
|
return $engine->paginate($this, $perPage, $page)->appends('query', $this->query);
|
||||||
@ -45,7 +47,7 @@ class ScoutBuilderMixin
|
|||||||
// Notice forPage call here. We use that to only get the records for the current page from db.
|
// Notice forPage call here. We use that to only get the records for the current page from db.
|
||||||
$results = $this->model->newCollection($engine->map(
|
$results = $this->model->newCollection($engine->map(
|
||||||
$this, $rawResults, $this->model
|
$this, $rawResults, $this->model
|
||||||
)->forPage($page, $perPage)->all());
|
)->forPage($page, $perPage)->values()->all());
|
||||||
|
|
||||||
return Container::getInstance()->makeWith(LengthAwarePaginator::class, [
|
return Container::getInstance()->makeWith(LengthAwarePaginator::class, [
|
||||||
'items' => $results,
|
'items' => $results,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user