Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Filter

private $likeOperator = 'LIKE';

public function __construct(public string $field, public ?string $value = null, public ?string $matchMode = self::CONTAINS)
public function __construct(public string $field, public $value = null, public ?string $matchMode = self::CONTAINS)
{
$this->likeOperator = \DB::connection()->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'pgsql' ? 'ILIKE' : 'LIKE';
}
Expand Down Expand Up @@ -114,14 +114,14 @@ private function applyWhere(Builder &$q, string $field, ?bool $or = false)
case self::NOT_CONTAINS:
if ($or) {
if(!$jsonField) {
$q->orWhere($field, "NOT" . $this->likeOperator, "%" . $this->value . "%");
$q->orWhere($field, "NOT " . $this->likeOperator, "%" . $this->value . "%");
}
else {
$q->orWhereRaw('LOWER('.$jsonField[0].'->>"$.'.$jsonField[1].'") NOT '.$this->likeOperator.' ?', mb_strtolower("%" . $this->value . "%"));
}
} else {
if(!$jsonField) {
$q->where($field, "NOT" . $this->likeOperator, "%" . $this->value . "%");
$q->where($field, "NOT " . $this->likeOperator, "%" . $this->value . "%");
}
else {
$q->whereRaw('LOWER('.$jsonField[0].'->>"$.'.$jsonField[1].'") NOT '.$this->likeOperator.' ?', mb_strtolower("%" . $this->value . "%"));
Expand Down Expand Up @@ -180,7 +180,11 @@ private function applyWhere(Builder &$q, string $field, ?bool $or = false)
}
break;
case self::IN:
//TODO: Implement
if ($or) {
$q->orWhereIn($field, $this->value);
} else {
$q->whereIn($field, $this->value);
}
break;
case self::LESS_THAN:
if ($or) {
Expand Down