From 70da2ebc29ed681b35cd2662ac738190d29fc82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20M=2E?= Date: Thu, 10 Oct 2024 17:53:43 +0200 Subject: [PATCH] Add fillPageItems --- src/Layout/Concerns/WithScroll.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Layout/Concerns/WithScroll.php b/src/Layout/Concerns/WithScroll.php index 0ddd982..82d80a8 100644 --- a/src/Layout/Concerns/WithScroll.php +++ b/src/Layout/Concerns/WithScroll.php @@ -19,13 +19,7 @@ trait WithScroll public function mountWithScroll(): void { if (blank($this->models)) { - $range = range(1, $this->getScrollLimit()); - - foreach ($range as $page) { - $this->mergePageItems($this->getPageItems($page)->all()); - - Sleep::for(100)->milliseconds(); - } + $this->fillPageItems(); } } @@ -73,6 +67,17 @@ protected function getPageItems(?int $page = null): LengthAwarePaginator ->paginate(perPage: 16, page: $page); } + protected function fillPageItems(): void + { + $range = range(1, $this->getScrollLimit()); + + foreach ($range as $page) { + $this->mergePageItems($this->getPageItems($page)->all()); + + Sleep::for(100)->milliseconds(); + } + } + protected function mergePageItems(array $models = []): void { $this->models = array_merge_recursive($this->models, $models);