简体   繁体   中英

SQL query to Eloquent conversion

如何将下面的SQL语句转换为Eloquent?

SELECT * FROM `messages` WHERE (`to`=$myID AND `from`=$guestID) OR (`to`=$guestID AND `from`=$myID)

Use where and orWhere closures for parameter grouping :

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM