你不能使用whereHas
查询生成器上下文中的方法。这whereHas
方法仅适用于Eloquent来自 Eloquent 模型及其关系的查询生成器。
你能做的就是使用joins
。所以你可以这样尝试:
$filterArray = explode("_", $filters);
$data['articles'] = \DB::table('products')->join('product_category', function ($q) {
$q->on('product_category.product_id', '=', 'products.id');
})->where('product_category.category_id', '=', $id)
->select('products.*')
->whereBetween('price_retail_1', array($priceFrom, $priceTo))
->join('filters', 'products.filter_id', '=', 'filters.filter_id')
->whereIn('filter_id', $filterArray);
->orderBy('products.' . $sort, $sortOrder)
->get();
我不知道你如何连接这两个表,所以这里只是示例数据:
->join('filters', 'products.filter_id', '=', 'filters.filter_id')