duanjianxi8439
2018-01-26 06:04
浏览 74
已采纳

如何将mysql查询转换为laravel?

Here my sql code:

SELECT favorites.id_user, specialities.specialities, university_datas.university_name 
FROM 
(
    (
        (
            favorites INNER JOIN programs ON programs.id=favorites.id_program
        ) 
        INNER JOIN specialities ON programs.id_specialities=specialities.id
    )
    INNER JOIN university_datas ON programs.id_univer=university_datas.id
) 

WHERE id_user=2;

I try with phpmyadmin and i get needed result but I can't convert to laravel

图片转代码服务由CSDN问答提供 功能建议

这里我的sql代码:

 <  code> SELECT favorites.id_user,specialities.specialities,university_datas.university_name 
FROM 
(
(
(
收藏INNER JOIN程序ON programs.id = favorites.id_program 
)
 INNER JOIN特色ON程序。  id_specialities = specialities.id 
)
 INNER JOIN university_datas ON programs.id_univer = university_datas.id 
)
 
WHERE id_user = 2; 
   
 
 

I 尝试使用phpmyadmin,我得到了所需的结果,但我无法转换为laravel

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doudou201701 2018-01-26 06:32
    已采纳
    $get_fav = DB::table('favorites')
    ->join('programs', 'favorites.id_program', '=', 'programs.id')
    ->join('specialities','programs.id_specialities', '=','specialities.id' )
    ->join('university_datas','programs.id_univer','=', 'university_datas.id')
    ->where('favorites.id_user', Auth::user()->id)
    ->select('favorites.id_user', 'specialities.specialities', 'university_datas.university_name')
    ->get();
    
    点赞 打赏 评论

相关推荐 更多相似问题