Eloquent Relationship of Laravel

Asked

Viewed 637 times

1

I have 3 tables:

-- tipos
id
nome

-- usuarios
id
tipo_id
nome
email

-- atividades
id
usuario_id
descricao

I’m using Eloquent to capture activity and activity user data:

$results = Atividades::with('Usuario')->get();

But I also need to get the type of user, I’ve tried:

$results = Atividades::with('Usuario')->with('Tipo')->get();

But it does not return user type data, only user data, someone would know how to do this query?

  • 1

    with('Usuario', 'Tipo')->get().

1 answer

1


You can put more than one parameter in the method with, do as follows:

$results = Atividades::with('Usuario', 'Tipo')->get();

To confirm you can consult the documentation of the Laravel.

Browser other questions tagged

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