From cd7c37801b16df6072c4fec16a04f7613755094a Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Mon, 26 Apr 2021 17:48:02 +0200 Subject: [PATCH 1/2] fix: use built-in where function --- src/Query/PaginationStrategy/WhereApplier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Query/PaginationStrategy/WhereApplier.php b/src/Query/PaginationStrategy/WhereApplier.php index c77d5c1..4cb4cdd 100644 --- a/src/Query/PaginationStrategy/WhereApplier.php +++ b/src/Query/PaginationStrategy/WhereApplier.php @@ -26,7 +26,7 @@ public function applyWhere() $comparator = $this->getComparatorForTarget($i); if ($i == 0) { - $this->query->whereRaw("`$column` $comparator ?", [$this->targets[$i]]); + $this->query->where($column, $comparator, $this->targets[$i]); } else { $this->applyWhereForColumnsAfterFirst($i); } From 6fa151b051da3315937c7c09728e80f4c65d8cd6 Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Mon, 26 Apr 2021 18:04:29 +0200 Subject: [PATCH 2/2] fix: use where also for multiple columns --- src/Query/PaginationStrategy/WhereApplier.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Query/PaginationStrategy/WhereApplier.php b/src/Query/PaginationStrategy/WhereApplier.php index 4cb4cdd..ce466d1 100644 --- a/src/Query/PaginationStrategy/WhereApplier.php +++ b/src/Query/PaginationStrategy/WhereApplier.php @@ -21,14 +21,22 @@ public function __construct($query, $targets, PaginationQueryAbstract $paginatio public function applyWhere() { - for ($i = 0; $i < count($this->targets); $i++) { + $targets = $this->targets; + for ($i = 0; $i < count($targets); $i++) { $column = $this->getOrderColumn($this->query, $i); $comparator = $this->getComparatorForTarget($i); if ($i == 0) { - $this->query->where($column, $comparator, $this->targets[$i]); + $this->query->where($column, $comparator, $targets[$i]); } else { - $this->applyWhereForColumnsAfterFirst($i); + $this->query->where(function ($query) use ($i, $column, $comparator, $targets) { + // Get previous column conditions + for ($j = 0; $j < $i; $j++) { + $query->where($this->getOrderColumn($this->query, $j), '=', $targets[$j]); + } + + $query->where($column, $comparator, $targets[$i]); + }, null, null, 'and not'); } } return $this->query;