select
*
from
`foundations`
inner join `foundation_sector` on
`foundation_sector`.`foundation_id` = `foundations`.`id`
inner join `sectors` on
`sectors`.`id` = `foundation_sector`.`sector_id`
GROUP BY
foundations.id
HAVING
SUM(sectors.title = 'x')
AND SUM(sectors.title = 'y')
То, что я пробовал, было
$postQuery = Foundation::query()
->join('foundation_sector', 'foundation_sector.foundation_id', '=', 'foundations.id')
->join('sectors', 'sectors.id', '=', 'foundation_sector.sector_id')
->groupBy('foundations.id')
->having('sectors.title', 'sum', $sectors, 'and');
, но это не сработало.