Skip to content

Commit bd06b05

Browse files
committed
fix
1 parent c8a1981 commit bd06b05

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Laravel/Filter/WhereCount.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tobyz\JsonApiServer\Laravel\Filter;
44

55
use Tobyz\JsonApiServer\Context;
6+
use Tobyz\JsonApiServer\Exception\BadRequestException;
67
use Tobyz\JsonApiServer\Schema\Filter;
78

89
class WhereCount extends Filter
@@ -29,6 +30,10 @@ public static function make(string $name): static
2930
public function apply(object $query, array|string $value, Context $context): void
3031
{
3132
foreach ($this->resolveOperators($value) as $operator => $val) {
33+
if (!is_scalar($val)) {
34+
throw new BadRequestException('Count filters require a single value');
35+
}
36+
3237
$query->whereHas(
3338
$this->relationship ?: $this->name,
3439
$this->scope ? fn($query) => ($this->scope)($query, $context) : null,

src/Laravel/Filter/WhereHas.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ public function apply(object $query, array|string $value, Context $context): voi
5959
$value = $this->resolveOperators($value);
6060

6161
foreach ($value as $operator => $v) {
62-
$method = in_array($operator, ['ne', 'notin', 'null']) ? 'whereDoesntHave' : 'whereHas';
62+
$method = match ($operator) {
63+
'ne', 'notin' => 'whereDoesntHave',
64+
'null', 'notnull' => ($operator === 'null' xor
65+
!filter_var($v, FILTER_VALIDATE_BOOLEAN))
66+
? 'whereDoesntHave'
67+
: 'whereHas',
68+
default => 'whereHas',
69+
};
6370

6471
$query->{$method}($field->property ?: $field->name, function ($query) use (
6572
$operator,

0 commit comments

Comments
 (0)