<?php

$attributeNames = ['good', 'bad', 'ugly'];
$products = Product::where(function ($query) use ($attributeNames) {
    foreach ($attributeNames as $attr) {
        $query->whereHas('attributes', function ($query) use ($attr) {
            return $query->where('name', $attr);
        });
    }
})->get();