Get data pivot table Laravel

0

How can I get the pivot table data using Laravel Eloquent? I need to know which setor_id of users and group_id linked

    
asked by anonymous 27.10.2018 / 03:14

1 answer

0

If I understand, I think this is what you need. I left in standard form and also in eloquent

select ug.setor_id, setors.nome, ug.group_id, groups.descricao 
from users_groups_has_users as ug 
inner join groups on groups.id = ug.group_id  
inner join setors on setors.id = ug.setors_id  

$query = DB::table('users_groups_has_users')->join('groups', 'join groups on groups.id', '=', 'users_groups_has_users.group_id')->join('setors', 'join setors on setors.id', '=', 'users_groups_has_users.setor_id')
->select('ug.setor_id', 'setors.nome', 'ug.group_id', 'groups.descricao')->get()
    
27.10.2018 / 04:02