Laravel nested queries, how to query three tables

1

I have three related tables like this: Table One related from one to many with Table2, Table2 related from one to many with TableTres.

How can I make a data query from Table Three with a condition to Table1. I'm really new at Laravel and I do not have much idea of what I have to do.

Try something like that, but ovio did not work.

return view('tabla3.index')
            ->with('TablaTres', $TablaTres -> where('id_tabla1', '4'));
    
asked by Neftalí García 09.10.2018 в 08:40
source

2 answers

0

you could use inner join $ users = DB :: table ('users')             - > join ('contacts', 'users.id', '=', 'contacts.user_id')             - > join ('orders', 'users.id', '=', 'orders.user_id')             - > select ('users. *', 'contacts.phone', 'orders.price')             -> get (); check the docs link

    
answered by 14.10.2018 / 04:21
source
0

If the condition depends on table one, that is, it is on its fields, you have to make the condition on that table and on the result get the relations to table 2 and from there to table 3, or not if you can put more information about the fields and the condition

    
answered by 14.10.2018 в 04:15