【发布时间】:2015-09-10 05:10:21
【问题描述】:
我有产品、子类别、类别关系..
在我定义 hasManyThrough 关系的类别模型中:
public function products()
{
return $this->hasManyThrough('Products','SubCategory');
}
如何在每个类别中仅显示 4 个产品?
$products = Category::with('products')->get()
我已经在 hasManyThrough 关系上添加了 take(2) 或 limit(2),但是查询限制了整体产品,而不是子类别。这是查询日志:
select products.*, subcategories.category_id from products inner join subcategories on subcategories.id = products.subcategory_id where subcategories.category_id in (?, ?, ?, ?, ?, ?) limit 4
【问题讨论】: