|
8 | 8 | use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
|
9 | 9 | use Illuminate\Contracts\Support\Arrayable;
|
10 | 10 | use Illuminate\Contracts\Support\Jsonable;
|
| 11 | +use Illuminate\Database\Eloquent\Builder; |
11 | 12 | use Illuminate\Http\Request;
|
12 | 13 | use Illuminate\Pagination\AbstractPaginator;
|
13 | 14 | use Illuminate\Support\Carbon;
|
@@ -164,8 +165,11 @@ public function getQueryData($builder)
|
164 | 165 |
|
165 | 166 | if ($this->cursor->getNextCursor()) {
|
166 | 167 | // If Cursor Points To Next
|
167 |
| - $query->take($limit) |
168 |
| - ->where($full_identifier_name, $this->identifier_sort_inverted ? '<' : '>', $this->cursor->getNextCursor()); |
| 168 | + $next_cursor = $this->cursor->getNextCursor(); |
| 169 | + |
| 170 | + $this->overrideCursorCondition($query, $full_identifier_name, $next_cursor, $this->identifier_sort_inverted); |
| 171 | + $query->take($limit); |
| 172 | + |
169 | 173 | } elseif ($this->cursor->getPrevCursor()) {
|
170 | 174 | // If Cursor Points To Prev
|
171 | 175 | $this->cursor->setDirection('prev');
|
@@ -629,4 +633,39 @@ protected function getCursorLink($cursor, $is_pointing_next = true)
|
629 | 633 |
|
630 | 634 | return $link . '?cursor=' . $cursor;
|
631 | 635 | }
|
| 636 | + |
| 637 | + /** |
| 638 | + * Overrides Cursor Condition with the new Cursor Value |
| 639 | + * |
| 640 | + * @param Builder $builder |
| 641 | + * @param string $full_identifier_name |
| 642 | + * @param int $next_cursor_value |
| 643 | + * @param bool $identifier_sort_inverted |
| 644 | + * |
| 645 | + * @return void |
| 646 | + */ |
| 647 | + protected function overrideCursorCondition( $builder , string $full_identifier_name, int $next_cursor_value, bool $identifier_sort_inverted): void |
| 648 | + { |
| 649 | + if($builder instanceof Builder) { |
| 650 | + $query = $builder->getQuery(); |
| 651 | + } else { |
| 652 | + $query = $builder; |
| 653 | + } |
| 654 | + |
| 655 | + $bindings = $query->getBindings(); |
| 656 | + |
| 657 | + if($query->wheres[count($query->wheres)-1]['column'] == $full_identifier_name) { |
| 658 | + $query->wheres[count($query->wheres)-1]['value'] = $next_cursor_value; |
| 659 | + $bindings[count($bindings)-1] = $next_cursor_value; |
| 660 | + } else { |
| 661 | + $query->where($full_identifier_name, $identifier_sort_inverted ? '<' : '>', $next_cursor_value); |
| 662 | + $bindings[] = $next_cursor_value; |
| 663 | + } |
| 664 | + |
| 665 | + $query->setBindings( $bindings ); |
| 666 | + |
| 667 | + if ($builder instanceof Builder) { |
| 668 | + $builder->setQuery($query)->withoutGlobalScopes(); |
| 669 | + } |
| 670 | + } |
632 | 671 | }
|
0 commit comments