fix text fields and exists operator
This commit is contained in:
+12
-50
@@ -198,35 +198,16 @@ final class FilterParser
|
||||
private function parseAnd(Builder $builder, array $arguments): Builder
|
||||
{
|
||||
|
||||
$ignoredFilters = [];
|
||||
foreach ($arguments as $argument) {
|
||||
if (in_array($argument->field, $ignoredFilters)) {
|
||||
continue;
|
||||
} else if ($argument->operator == "in") {
|
||||
if ($argument->operator == "in") {
|
||||
$builder->whereIn($argument->field, $argument->value);
|
||||
} else if ($argument->operator == "nin") {
|
||||
$builder->whereNotIn($argument->field, $argument->value);
|
||||
} elseif ($argument->operator == "eqobject") {
|
||||
|
||||
$object = $argument->value;
|
||||
// unset related filters used here
|
||||
$addToIgnored = collect($arguments)
|
||||
->filter(fn(Argument $f) => str_starts_with($f->field, $object))
|
||||
->values()
|
||||
->map(fn($f) => $f->field)
|
||||
->toArray();
|
||||
|
||||
$ignoredFilters = array_merge($ignoredFilters, $addToIgnored);
|
||||
|
||||
$objectFilters = collect($arguments)
|
||||
->filter(fn($f) => str_starts_with($f->field, $object))
|
||||
->values()
|
||||
->reduce(function ($c, $f) use ($object) {
|
||||
$field = str_replace($object . "->", "", $f->field);
|
||||
$c[$field] = $f->value;
|
||||
return $c;
|
||||
});
|
||||
|
||||
} else if ($argument->operator == "exists") {
|
||||
$builder->where($argument->field, "!=", "");
|
||||
$builder->where($argument->field, "!=", null);
|
||||
} elseif ($argument->operator == "filter") {
|
||||
$builder->whereJsonContains($argument->field, [$argument->value]);
|
||||
// target result
|
||||
// filter[data.previousNames_object]=previousNames&filter[previousNames.name_eq]=alpha&filter[previousNames.id_eqnum]=24
|
||||
// $query->whereJsonContains("data->previousNames", [["name" => "alpha", "id" => 24]]);
|
||||
@@ -245,35 +226,16 @@ final class FilterParser
|
||||
private function parseOr(Builder $builder, array $arguments): Builder
|
||||
{
|
||||
$builder->where(function (Builder $orBuilder) use ($arguments) {
|
||||
$ignoredFilters = [];
|
||||
foreach ($arguments as $argument) {
|
||||
if (in_array($argument->field, $ignoredFilters)) {
|
||||
continue;
|
||||
} else if ($argument->operator == "in") {
|
||||
if ($argument->operator == "in") {
|
||||
$orBuilder->orWhereIn($argument->field, $argument->value);
|
||||
} else if ($argument->operator == "nin") {
|
||||
$orBuilder->orWhereNotIn($argument->field, $argument->value);
|
||||
} elseif ($argument->operator == "eqobject") {
|
||||
|
||||
$object = $argument->value;
|
||||
// unset related filters used here
|
||||
$addToIgnored = collect($arguments)
|
||||
->filter(fn(Argument $f) => str_starts_with($f->field, $object))
|
||||
->values()
|
||||
->map(fn($f) => $f->field)
|
||||
->toArray();
|
||||
|
||||
$ignoredFilters = array_merge($ignoredFilters, $addToIgnored);
|
||||
|
||||
$objectFilters = collect($arguments)
|
||||
->filter(fn($f) => str_starts_with($f->field, $object))
|
||||
->values()
|
||||
->reduce(function ($c, $f) use ($object) {
|
||||
$field = str_replace($object . "->", "", $f->field);
|
||||
$c[$field] = $f->value;
|
||||
return $c;
|
||||
});
|
||||
|
||||
} else if ($argument->operator == "exists") {
|
||||
$orBuilder->where($argument->field, "!=", "");
|
||||
$orBuilder->where($argument->field, "!=", null);
|
||||
} elseif ($argument->operator == "filter") {
|
||||
$orBuilder->whereJsonContains($argument->field, [$argument->value]);
|
||||
// target result
|
||||
// filter[data.previousNames_object]=previousNames&filter[previousNames.name_eq]=alpha&filter[previousNames.id_eqnum]=24
|
||||
// $query->whereJsonContains("data->previousNames", [["name" => "alpha", "id" => 24]]);
|
||||
|
||||
Reference in New Issue
Block a user