I'm having some trouble getting my eloquent query right. Let's say I have an array of ID's:
$features_array = [1, 4, 6]
Using a whereIn() as below, I've build a query that returns items that match any ID in the $features_array.
But how would you get only the items that have all features in the array?
Items::select('*')
->when($features, function ($query, $features) {
return $query->whereHas('features', function ($query) use ($features) {
$query->whereIn('id', $features);
});
})->distinct()->get();