【发布时间】:2016-11-07 05:02:22
【问题描述】:
我遇到了这个 whereIn 的问题。我的代码是这样的
$arrayKeys = [1, 2, 1, 4, 5, 1];
$products = \App\Product::whereIn('id', $arrayKeys)
->select(['id', 'name', 'outright_price', 'discount', ])
->with('photo', 'colors')
->get();
它只返回唯一的id 1、2、4、5。我需要返回1、2、1、4、5、1。怎么做?我没有任何想法。
【问题讨论】:
-
只返回 1,2,4,5 是什么意思?您的意思是记录 1、2、4 和 5?
-
是的,来自数据库的记录。
-
我得到了记录 id 1, 2, 4, 5 但我需要 1, 2, 1, 4, 5, 1 。我认为它不能通过 whereIn 来完成,但我怎样才能实现这些记录。谢谢。
-
您可以使用循环遍历数组,甚至可以使用 Like 子句?
标签: laravel