laravel,如何使用所有值 select

laravel, how to select with all values

whereIn returns product_id 如果它在 $property_values 中有任何 property_option_id。如何 return 如果它全部来自 $property_values?

/*
arr int $property_values
 
db property_product_values
id, product_id, property_option_id
*/ 
    
$query->select('property_values.product_id')
                ->from('property_values')
                ->whereColumn('property_values.product_id', 'products.id')
                ->whereIn("property_values.property_option_id", $property_values);

如果 product_idproperty_option_id 没有重复条目,此解决方案将 return product_ids 具有所有 属性 值。

$query->select('property_values.product_id')
    ->from('property_values')
    ->whereIn('property_values.property_option_id', $property_values)
    ->groupBy('property_values.product_id')
    ->having(DB::raw('count(product_id)'), '>=', count($property_values))
    ->pluck('property_values.product_id');