Skip to content
Merged
Show file tree
Hide file tree
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/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@ public function whereNestedDoc($column, $query, $boolean = 'and'): self
return $this;
}

/**
* Add a 'must not' statement to the query.
*
* @param \Illuminate\Database\Query\Builder|static $query
* @param string $boolean
* @return self
*/
public function whereNot($query, $boolean = 'and'): self
{
$type = 'Not';

call_user_func($query, $query = $this->newQuery());

$this->wheres[] = compact('query', 'type', 'boolean');

return $this;
}

/**
* Add a prefix query
*
Expand Down
28 changes: 28 additions & 0 deletions src/QueryGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,37 @@ protected function compileWhereNestedDoc(Builder $builder, $where): array

$query['nested'] = array_merge($query['nested'], array_filter($wheres));

if (isset($where['operator']) && $where['operator'] === '!=') {
$query = [
'bool' => [
'must_not' => [
$query
]
]
];
}

return $query;
}

/**
* Compile a where not clause
*
* @param Builder $builder
* @param array $where
* @return array
*/
protected function compileWhereNot(Builder $builder, $where): array
{
return [
'bool' => [
'must_not' => [
$this->compileWheres($where['query'])['query']
]
]
];
}

/**
* Get value for the where
*
Expand Down