有一个雄辩的问题。有要求
$item = Store::select('id','name')
->with(['product.cart' => function ($query) use($cartWhere) {
$query->where($cartWhere);
}])
->whereHas('product.cart', function ($query) use($cartWhere) {
$query->where($cartWhere);
})
->get();
和来自 product.cart 的中间链产品我收到了
select * from `products` where `products`.`store_id` in (2, 3, 4) and `products`.`deleted_at` is null
但是为什么雄辩地忽略我的-> whereHas 过滤器?正确存储已过滤的商品,正确选择购物车的过滤器,但产品将其忽略。如何使我收到一个需要我的唯一产品(存在于购物车中)。购物车表具有product_id外键
我能通过雄辩做到这一点吗?还是我需要使用原始SQL并手动进行设置?
EDIT v1:其他信息
产品表的列为 store_id 购物车表具有列 product_id ,数量, site_id , user_id , id >
$ cartWhere 变量
$cartWhere['site_id'] =$current_site_id;
$cartWhere['user_id'] = $user_id;