这里是我的sql代码:

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;

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

最佳答案

$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();

关于php - 如何将mysql查询转换为laravel?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48456460/

10-15 00:28