@bobbybouwmann . Your solution will not work. The correct Mysql query will be
For Scenario 1
SELECT *
FROM creatives
WHERE creative_id IN (SELECT creative_id
FROM term_relationships
WHERE term_id IN (1)
GROUP BY creative_id
HAVING COUNT(*) = 1)
For Scenario 2
SELECT *
FROM creatives
WHERE creative_id IN (SELECT creative_id
FROM term_relationships
WHERE term_id IN (1, 2)
GROUP BY creative_id
HAVING COUNT(*) = 2)
For Scenario 3
SELECT *
FROM creatives
WHERE creative_id IN (SELECT creative_id
FROM term_relationships
WHERE term_id IN (1, 2, 3)
GROUP BY creative_id
HAVING COUNT(*) = 3)
I don't have a prior knowledge of how many filters will be selected by the user.
So how do you build this query in Laravel? I can use Raw query but really don't want to if it can be done more elegantly. Thanks