Skip to content

Commit d6390ae

Browse files
NorgulStyleCIBot
andauthored
Where not exists hack (#40)
* Laravel 9 PHP 8 upgrade #major * Where not exists hack * Apply fixes from StyleCI Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent 530db81 commit d6390ae

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ following:
6969
JSON key-value pair.
7070
- It is possible to search by related models using ``.`` as a divider i.e.
7171
`"relation.column": "operator value")`. **Note** this will execute a `WHERE EXISTS`, it will
72-
not filter resulting relations if included within relations.
72+
not filter resulting relations if included within relations. To do a ``WHERE NOT EXISTS`` you can ue `!relation.column`.
7373
- ``operator`` is one of the available main operators for querying (listed [below](#main-operators))
7474
- ``values`` is a semicolon (`;`) separated list of values
7575
(i.e. `"column": "=value;value2;value3"`) which

src/SearchCallbacks/AbstractCallback.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
abstract class AbstractCallback
1414
{
15-
protected Builder $builder;
16-
protected SearchParser $searchParser;
15+
protected Builder $builder;
16+
protected SearchParser $searchParser;
1717
protected CategorizedValues $categorizedValues;
1818

1919
/**
@@ -33,6 +33,13 @@ public function __construct(Builder $builder, SearchParser $searchParser)
3333
$this->builder->when(
3434
str_contains($this->searchParser->column, '.'),
3535
function (Builder $builder) {
36+
// Hack for whereDoesntHave relation, doesn't work recursively.
37+
if (str_contains($this->searchParser->column, '!') !== false) {
38+
$this->searchParser->column = str_replace('!', '', $this->searchParser->column);
39+
$this->appendRelations($builder, $this->searchParser->column, $this->categorizedValues, 'orWhereDoesntHave');
40+
41+
return;
42+
}
3643
$this->appendRelations($builder, $this->searchParser->column, $this->categorizedValues);
3744
},
3845
function (Builder $builder) {

0 commit comments

Comments
 (0)