diff --git a/src/Models/Concerns/WithPaginateScroll.php b/src/Models/Concerns/WithPaginateScroll.php new file mode 100644 index 0000000..3ddf033 --- /dev/null +++ b/src/Models/Concerns/WithPaginateScroll.php @@ -0,0 +1,63 @@ +getBuilder() instanceof Builder || ! $this->getBuilder() instanceof Scout) + ); + } + + public function updatedPage(): void + { + $this->fetch(); + } + + public function isFetchable(): bool + { + if ($this->items->isEmpty()) { + return true; + } + + return $this->getBuilder()->hasMorePages(); + } + + public function clear(): void + { + $this->reset('fetchCount'); + + $this->resetPage(); + + $this->models = collect(); + + unset($this->items); + } + + protected function getMergeCandidates(): Collection + { + return $this->getBuilder()->getCollection(); + } + + protected function getBuilder(): Paginator + { + return $this->getQuery() + ->simplePaginate( + perPage: $this->getCandidatesLimit(), + page: $this->getPage(), + ); + } +}