Answer the question
In order to leave comments, you need to log in
How to complete a request?
There is a Person model that is connected to the Genre models through a many-to-many relationship.
In the search query, I need to find people who have all the specified "genres" by the user.
I did it like this
$results = $results->whereHas('genres', function ($query) use ($request){
$query->whereIn('name', array_column($request->genres, 'name'));
});
Answer the question
In order to leave comments, you need to log in
$relations_ids = [1, 2, 3];
Place::whereHas('comforts', function ($query) use ($relations_ids) {
$query->whereIn('id', $relations_ids);
}, '>=', count($relations_ids))->get();
Place::whereHas('comforts', function ($query) use ($relations_ids) {
$query->whereIn('id', $relations_ids[0]);
})->whereHas('comforts', function ($query) use ($relations_ids) {
$query->whereIn('id', $relations_ids[1]);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question