title: How to convert query with many joins and inner select to Laravel ORM
body: <p>Hi guys please help solve this problem.
  Need to convert this query to Laravel ORM.</p>
  <pre><code>$user = Auth::user();
  $datas = DB::select('select * from kvits k
                  left join (select o.kvit_id, sum(o.amount * o.price) as sum from operations o
                  group by o.kvit_id) s on k.id = s.kvit_id
                  left join users u on k.user_id = u.id
                  left join users h on k.hamkor_id = h.id
                  left join stores s2 on k.store_id = s2.id
                  where k.user_id = ' $user-&gt;id  ');
  </code></pre>
  <p>Main problem is how to convert this query to Larave ORM.
  Basically this part</p>
  <pre><code>left join (select o.kvit_id, sum(o.amount * o.price) as sum from operations o
              group by o.kvit_id) s on k.id = s.kvit_id
  </code></pre>
  <p>Second problem is:
  Why Laravel getting the last join id in the column without taking all the ids (e.g. k.id, ****, u.id, ***, s.id on this query). And does not display data from all other joined columns.
  How to get them.</p>
  <p><a href="https://i.stack.imgur.com/0WOSa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0WOSa.png" alt="Here is dd($datas) photo " /></a></p>
  <p>I want to get data all joined tables also, like <code>k.id, k.date, ... u.id, u.name, .... s.id, s.name, s.notes </code>.  Like belowed table.
  <a href="https://i.stack.imgur.com/AXMvM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AXMvM.png" alt="enter image description here" /></a></p>