0
I tried anyway, but he won’t ride for me SubSelect
. I used the method toSql()
to confirm and really he does not ride.
SQL
SELECT p.descr,p.dt_hr, (SELECT u1.name FROM users u1 WHERE u1.id = f.id_friend) AS name
FROM friends f JOIN users u ON u.id = f.id_user
JOIN posts p ON p.id_user = f.id_friend
WHERE u.id = 1
ORDER BY p.dt_hr DESC
I tried this query here, but without result. $posts = DB::table('Friends') ->select('Friends.*') ->addSelect(DB::raw("(SELECT U1.name FROM users U1 WHERE U1.id = Friends.id_friend) AS name")) ->Join('users', 'users.id', '=', 'Friends.id_user') ->Join('posts', 'posts.id_user', '=', 'Friends.id_friend') ->select('posts.dt_hr', 'posts.descr', 'name')
->Where('users.id', $id_user) ->orderby('posts.dt_hr', 'desc') ->get();
– Leonardo
RESOLVED NOW: $posts = DB::table('Friends') ->select('posts.dt_hr', 'posts.descr', 'name', (DB::raw("(SELECT U1.name FROM users U1.id = Friends.id_friend) AS name")) ->Join('users', 'users.id', '=', 'Friends.id_user') ->Join('posts', 'posts.id_user', '=', 'Friends.id_friend') ->Where('users.id', $id_user) ->orderby('posts.dt_hr', 'desc') ->get();
– Leonardo
Put as reply @Leonardo ... then ...
– novic