Skip to content

Commit

Permalink
Apply Eloquent resource scope when applying relationship filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyzerner committed Jul 11, 2024
1 parent 8885c35 commit e913512
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Laravel/Filter/WhereHas.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function apply(object $query, array|string $value, Context $context): voi
$query->{static::QUERY_BUILDER_METHOD}($field->property ?: $field->name, function (
$query,
) use ($value, $relatedCollection, $context) {
if ($relatedCollection instanceof EloquentResource) {
$relatedCollection->scope($query, $context);
}

if (array_is_list($value)) {
$query->whereKey(array_merge(...array_map(fn($v) => explode(',', $v), $value)));
} else {
Expand Down

0 comments on commit e913512

Please sign in to comment.