Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SQL查询到雄辩转换_Php_Sql_Laravel_Eloquent - Fatal编程技术网

Php SQL查询到雄辩转换

Php SQL查询到雄辩转换,php,sql,laravel,eloquent,Php,Sql,Laravel,Eloquent,如何将下面的SQL语句转换为雄辩的语句 SELECT * FROM `messages` WHERE (`to`=$myID AND `from`=$guestID) OR (`to`=$guestID AND `from`=$myID) 使用where和或where闭包: 使用where和或where闭包: 使用嵌套查询。我建议从文档开始,使用嵌套查询。我建议从文档和 Message::where(function($q) use($myId, $guestId) { $q->

如何将下面的SQL语句转换为雄辩的语句

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

使用
where
或where
闭包:


使用
where
或where
闭包:


使用嵌套查询。我建议从文档开始,使用嵌套查询。我建议从文档和
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();