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
18 changes: 18 additions & 0 deletions src/QueryBuilderParser/QueryBuilderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class QueryBuilderParser

protected $fields;

protected $useHaving = false;

/**
* @param array $fields a list of all the fields that are allowed to be filtered by the QueryBuilder
*/
Expand All @@ -21,6 +23,18 @@ public function __construct(array $fields = null)
$this->fields = $fields;
}

/**
* Use "having" instead of "where" in the queries.
*
* @return QueryBuilderParser
*/
public function setUseHaving()
{
$this->useHaving = true;

return $this;
}

/**
* QueryBuilderParser's parse function!
*
Expand Down Expand Up @@ -253,6 +267,10 @@ protected function convertIncomingQBtoQuery(Builder $query, stdClass $rule, $val
return $this->makeQueryWhenNull($query, $rule, $sqlOperator, $condition);
}

if ($this->useHaving) {
return $query->having($rule->field, $sqlOperator['operator'], $value, $condition);
}

return $query->where($rule->field, $sqlOperator['operator'], $value, $condition);
}

Expand Down