如何在laravel中进行此查询?

时间:2016-12-19 09:07:50

标签: laravel eloquent

如何在laravel

中将其转换为雄辩的ORM
SELECT * FROM (
   SELECT * FROM chat 
    WHERE (userID = $session AND toID = $friendID) 
    OR (userID = $friendID AND toID = $session)  
    ORDER BY id DESC
    LIMIT 10
 ) AS `table` ORDER by id ASC

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

$sql = "SELECT * FROM ( SELECT * FROM chat WHERE (userID = $session AND toID = $friendID) OR (userID = $friendID AND toID = $session)
ORDER BY id DESC LIMIT 10 ) AS table ORDER by id ASC";

$result = DB::select(DB::raw($sql))

$ result变量包含您的输出。您必须使用数据库类

use DB;