如何将以下SQL语句转换为Eloquent?
SELECT * FROM `messages` WHERE (`to`=$myID AND `from`=$guestID) OR (`to`=$guestID AND `from`=$myID)
答案 0 :(得分:4)
对parameter grouping使用where
和orWhere
个闭包:
Message::where(function($q) use($myId, $guestId) {
$q->where('to', $myId)->where('from', $guestId);
})
->orWhere(function($q) use($myId, $guestId) {
$q->where('to', $guestId)->where('from', $myId);
})
->get();