Transform Inner Join Join to Join Laravel

0

I am updating a system that is developed in pure PHP and I am putting it in Laravel, however, I had never done more than one join and with "AND" parameters so I would like to be helped, how can I put this SELECT in the controller Laravel?

<?php 
  $users = "SELECT * FROM ma_usuario u, ma_user_tipo t, ma_user_tipo_rel r 
            WHERE ma_user_tipo.tp_usr_id=ma_user_tipo_rel.tp_usr_id 
            AND ma_usuario.usr_id=ma_user_tipo_rel.usr_id 
            AND ma_usuario.usr_status='Ativo' 
            AND r.tp_usr_id='$id' 
            ORDER BY u.usr_id";
 ?>

As many parameters have had a knot in the brain and I did not understand how to mount.

    
asked by anonymous 13.10.2017 / 12:00

1 answer

0

Following the documentation ( link ) you can do your query this way:

DB::table('ma_usuario')
    ->join('ma_user_tipo_rel' 'ma_usuario.usr_id', '=', 'ma_user_tipo_rel.usr_id')
    ->where([
        ['ma_usuario.usr_status', '=', 'Ativo'],
        ['ma_user_tipo_rel.tp_usr_id', '=', $id],
    ])
    ->orderBy('ma_usuario.usr_id');
    
13.10.2017 / 13:03