Question from Laracasts forum, let's try to solve it.
Imagine 2 models: Product and Attribute (BelongsToMany relationship)
See database data in the "Code snippet" section.
When filter products, user select RAM => [4GB, 8GB] and HDD => 256GB.
Goal is to get products that have (RAM - 4GB OR RAM - 8GB) AND (HDD - 256GB). In the database example, I should get products with ID 1 and 2 (Product 3 have RAM 4GB but doesn't have HDD 256, so doesn't count).
Please write Eloquent query for this, so something like:
$products = Product::whereHas [...some magic...] ->get();