Reputation: 15
How do I transform below SQL statement to Eloquent?
SELECT * FROM `messages` WHERE (`to`=$myID AND `from`=$guestID) OR (`to`=$guestID AND `from`=$myID)
Upvotes: 0
Views: 47
Reputation: 163768
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();
Upvotes: 4