【发布时间】:2018-05-17 19:17:20
【问题描述】:
我正在尝试使用多个 whereNotIn 数组进行查询。由于某种原因,它们相互阻塞并忽略其他查询参数。
关于如何解决这个问题的任何线索?
$products = Products::orderBy('id','DESC')
->where('status', '=', 4)
->whereNotIn('category', $excluded)
->whereNotIn('location', ['New York', 'Boston', 'Washington, DC', 'Charlotte'])
->take(400)
->get();
【问题讨论】:
-
你说的他们互相屏蔽是什么意思?
-
例如,我得到了status不是4,并且没有排除category的产品。
-
好的。使用
->toSql()代替->get()和dd结果。它会告诉你正在运行什么查询。 -
select * from
productswherestatus= ?和category不在 (?) 和location不在 (?, ?, ?, ?) 中,按iddesc 限制 400 排序 -
确实很奇怪。
$excluded的值是多少?不过,查询本身看起来不错。
标签: php sql laravel laravel-5 eloquent