Skip to content

Commit 68891a5

Browse files
committed
Apply relationship scope
1 parent 516ec31 commit 68891a5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Laravel/Filter/WhereHas.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use LogicException;
66
use Tobyz\JsonApiServer\Context;
77
use Tobyz\JsonApiServer\Laravel\EloquentResource;
8+
use Tobyz\JsonApiServer\Laravel\Field\ToMany;
9+
use Tobyz\JsonApiServer\Laravel\Field\ToOne;
810
use Tobyz\JsonApiServer\Schema\Field\Relationship;
911
use Tobyz\JsonApiServer\Schema\Filter;
1012

@@ -72,14 +74,16 @@ public function apply(object $query, array|string $value, Context $context): voi
7274
$operator,
7375
$v,
7476
$relatedCollection,
77+
$field,
7578
$context,
7679
) {
7780
if ($relatedCollection instanceof EloquentResource) {
7881
$relatedCollection->scope($query, $context);
7982
}
8083

81-
// TODO: apply relationship scope
82-
// TODO: allow applying custom scope
84+
if (($field instanceof ToMany || $field instanceof ToOne) && $field->scope) {
85+
($field->scope)($query, $context);
86+
}
8387

8488
if (in_array($operator, ['null', 'notnull'])) {
8589
return;

0 commit comments

Comments
 (0)