Pick up data pivot table Laravel

Asked

Viewed 344 times

0

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

inserir a descrição da imagem aqui

  • Put the part of the Models code where you made the relationships, it’s easier to help you. ;)

1 answer

0

If I understand, I think this is what you need. I left in the standard form and also in the 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()
  • Eloquent or Querybuilder?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.