【发布时间】:2019-08-20 23:09:24
【问题描述】:
从数据库中随机选择新产品时,我的查询运行良好。但是为了防止重复,在我看来,我在页面上传递了一个已经在销售的产品的 JSON 对象。我希望我的查询基本上查询我的数据库以查找待售产品,但也不在已经待售的产品集合中。
这部分工作得很好
$nproduct = Product::whereIn('seller_id', Auth::user()->samegroup())->inRandomOrder()->first();
$nprice = $nproduct->price;
$nquantity = $nproduct->quantity_available;
$nid = $nproduct->id;
$nseller = $nproduct->seller_id;
但我在尝试确保我的查询不包含 $products_already_for_sale 中的任何内容时遇到了困难
$products_already_for_sale = $request->current_product_ids;
【问题讨论】:
-
你为什么要用
whereIn和first()?whereIn用于当您有多个时。