Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.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
将Mysql查询转换为Laravel 5雄辩?_Mysql_Laravel 5_Eloquent - Fatal编程技术网

将Mysql查询转换为Laravel 5雄辩?

将Mysql查询转换为Laravel 5雄辩?,mysql,laravel-5,eloquent,Mysql,Laravel 5,Eloquent,我在应用程序中使用了Laravel 5.1。我的MySQL查询是 "Select * from " . "(Select u.* from " . "( " . "SELECT u2.id as user_id, u2.fname as fname, u2.lname as lname, u2.uname as uname, u2.email as email, u2.address as address, u2.city_id as city_i

我在应用程序中使用了Laravel 5.1。我的MySQL查询是

"Select * from "
        . "(Select u.* from "
        . "( "
        . "SELECT u2.id as user_id, u2.fname as fname, u2.lname as lname, u2.uname as uname, u2.email as email, u2.address as address, u2.city_id as city_id, u2.website as website FROM users u1, users u2 where u1.city_id = u2.city_id && u1.id = '$this->current_user_id' ) 
            u left join follows f on u.user_id = f.following_id where f.following_id is null 
            UNION
            Select uu.id as user_id, uu.fname as fname, uu.lname as lname, uu.uname as uname, uu.email as email, uu.address as address, uu.city_id as city_id, uu.website as website from users uu where uu.id in (Select u.user_id from (SELECT user_id FROM reviews group by user_id order by count(user_id) desc5
            ) u left join follows f on u.user_id=f.following_id where f.following_id is null
            )
            ) 
            T LIMIT 5"

如何将其转换为Laravel Eloquent?

该查询在功能上与此查询相同:

SELECT u2.id user_id
     , u2.fname 
     , u2.lname 
     , u2.uname 
     , u2.email 
     , u2.address 
     , u2.city_id 
     , u2.website 
  FROM users u1
  JOIN users u2 
    ON u2.city_id = u1.city_id 
  LEFT
  JOIN follows f 
    ON f.following_id = u.user_id 
 WHERE f.following_id is null 
 UNION
SELECT uu.id user_id
     , uu.fname 
     , uu.lname 
     , uu.uname 
     , uu.email 
     , uu.address 
     , uu.city_id 
     , uu.website 
  FROM users uu
  JOIN 
     ( SELECT r.user_id 
         FROM reviews r
         LEFT
         JOIN follows f
           ON f.following_id = r.user_id 
        WHERE f.following_id IS NULL
        GROUP 
           BY user_id 
        ORDER 
           BY COUNT(user_id) DESC 
        LIMIT 5
     ) x
    ON x.user_id = uu.id;

您是否尝试转换它?desc5??有口才的是ORM。所以你需要和。但是我想把laravel Elount…转换成Me?似乎更容易。此外,有没有某种DB::raw()功能请参见此链接