Eloquent: require all IDs when filtering a hasMany relationship

This commit is contained in:
Toby Zerner 2021-05-05 14:18:58 +09:30
parent 8215cfb0ff
commit cdb910fdda
1 changed files with 5 additions and 3 deletions

View File

@ -184,9 +184,11 @@ class EloquentAdapter implements AdapterInterface
$relatedKey = $relation->getRelated()->getQualifiedKeyName();
if (count($ids)) {
$query->whereHas($property, function ($query) use ($relatedKey, $ids) {
$query->whereIn($relatedKey, $ids);
foreach ($ids as $id) {
$query->whereHas($property, function ($query) use ($relatedKey, $id) {
$query->where($relatedKey, $id);
});
}
} else {
$query->whereDoesntHave($property);
}