Answer the question
In order to leave comments, you need to log in
Laravel correct whereHas?
Hello, there is a database of entities groups, they have tags, you need to make a selection of all entities that either have no tags at all or have tags, except for the excluded ones
$entities = Entity::whereHas('tags', function($query) use ($excluded) {
$query->whereNotIn('tags.id', $excluded);
});
Answer the question
In order to leave comments, you need to log in
$entities = Entity::where(function($q) use ($excluded){
$q->whereHas('tags', function($query) use ($excluded) {
$query->whereNotIn('tags.id', $excluded);
})->orWhereDoesntHave('tags');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question