【发布时间】:2020-07-29 14:51:33
【问题描述】:
我是 laravel 的新手,我在使用它的查询生成器时遇到了问题。我正在运行这段代码
return DB::table('t_chat')
->where('chat_msg_from', '=', auth()->user()->id)
->where('chat_msg_to', '=', $to_id)
->orWhere('chat_msg_from', '=', $to_id)
->where('chat_msg_to', '=', auth()->user()->id)
->get();
此代码将运行如下查询:
SELECT * FROM t_chat WHERE chat_msg_to = 2 AND chat_msg_from = 1
OR
chat_msg_to = 1 AND chat_msg_from = 2
但我想要这样:
SELECT * FROM t_chat WHERE (chat_msg_to = 2 AND chat_msg_from = 1)
OR
(chat_msg_to = 1 AND chat_msg_from = 2)
【问题讨论】:
-
请注意,您不需要任何额外的括号。
标签: sql database laravel where-clause brackets