Commit b0b6225 1 parent e948929 commit b0b6225 Copy full SHA for b0b6225
File tree 1 file changed +63
-0
lines changed
1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Foxws \WireUse \Models \Concerns ;
4
+
5
+ use Illuminate \Database \Eloquent \Builder ;
6
+ use Illuminate \Support \Collection ;
7
+ use Illuminate \Pagination \Paginator ;
8
+ use Laravel \Scout \Scout ;
9
+ use Livewire \WithPagination ;
10
+
11
+ trait WithPaginateScroll
12
+ {
13
+ use WithQueryBuilder;
14
+ use WithPagination;
15
+ use WithScroll;
16
+
17
+ public function bootWithPaginateScroll (): void
18
+ {
19
+ throw_if (
20
+ ! method_exists ($ this , 'getBuilder ' ) ||
21
+ ! ($ this ->getBuilder () instanceof Builder || ! $ this ->getBuilder () instanceof Scout)
22
+ );
23
+ }
24
+
25
+ public function updatedPage (): void
26
+ {
27
+ $ this ->fetch ();
28
+ }
29
+
30
+ public function isFetchable (): bool
31
+ {
32
+ if ($ this ->items ->isEmpty ()) {
33
+ return true ;
34
+ }
35
+
36
+ return $ this ->getBuilder ()->hasMorePages ();
37
+ }
38
+
39
+ public function clear (): void
40
+ {
41
+ $ this ->reset ('fetchCount ' );
42
+
43
+ $ this ->resetPage ();
44
+
45
+ $ this ->models = collect ();
46
+
47
+ unset($ this ->items );
48
+ }
49
+
50
+ protected function getMergeCandidates (): Collection
51
+ {
52
+ return $ this ->getBuilder ()->getCollection ();
53
+ }
54
+
55
+ protected function getBuilder (): Paginator
56
+ {
57
+ return $ this ->getQuery ()
58
+ ->simplePaginate (
59
+ perPage: $ this ->getCandidatesLimit (),
60
+ page: $ this ->getPage (),
61
+ );
62
+ }
63
+ }
You can’t perform that action at this time.
0 commit comments