Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RamjithAp's avatar

Eloguent query replacement for my raw query

What can be the best replacement if I use modal relationships for below query and what is the disadvantage if I use below.

$games = DB::table('xx') ->join('yy', 'xx.yy_id', '=', 'yy.id') ->where('xx.search_id','=',$id) ->join('uu', 'yy.id', '=', 'uu.yy_id') ->join('zz', 'uu.id', '=', 'zz.uu_id') ->select('zz.*','uu.name as category') ->get();

0 likes
1 reply
Snapey's avatar

unfortunately for you, people really hate answering questions with hypothetical object names

The advantage using eloquent is a much simpler statement that is easily understood by yourself and othe programmers

The advantage with multiple joins is a more compact result set and possibly a more efficient query

Please or to participate in this conversation.