Skip to content

Commit 35193fa

Browse files
committed
Validate that WhereBelongsTo filter input is a list
1 parent fcc0a31 commit 35193fa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Laravel/Filter/WhereBelongsTo.php

Lines changed: 8 additions & 1 deletion
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 WhereBelongsTo extends Filter
@@ -25,9 +26,15 @@ public function apply(object $query, array|string $value, Context $context): voi
2526
{
2627
$relationship = $query->getModel()->{$this->relationship ?: $this->name}();
2728

29+
if (!array_is_list($values = (array) $value)) {
30+
throw new BadRequestException('filter value must be list', [
31+
'parameter' => "filter[$this->name]",
32+
]);
33+
}
34+
2835
$query->whereIn(
2936
$relationship->getQualifiedForeignKeyName(),
30-
array_merge(...array_map(fn($v) => explode(',', $v), (array) $value)),
37+
array_merge(...array_map(fn($v) => explode(',', $v), $values)),
3138
);
3239
}
3340
}

0 commit comments

Comments
 (0)