How can I get information using laravel with chained join?

0

I have 3 layers of entities, of which I only want the third object. but based on information from the first two.

For example, I have a factory that makes cars, and each car has a type of wheel. I want all the wheels manufactured by a factory.

I do not know how to do this using eloquent, the only idea I had was to do several hasMany to get this data. but I fear it is not the most efficient way because I will end up getting data that will not be used.

I tried this but it did not work out as well as I wanted.

DB::raw('select results from hectars h,consultas c,results r where h.id_fazendeiro=? and h.id=c.id_hectar and c.id = r.id_consulta',[$id]);
    
asked by anonymous 01.06.2018 / 13:19

1 answer

0

You can use the select () method to pull only the information you want, and the join () method to bind your query to another table.

link

    
01.06.2018 / 23:31