How to retrieve data from multiple tables using laravel query building

103 views Asked by At

I have 2 records in each table. when i tried this below query  

$result = DB::table('table1')
          ->join('table2','table1.user_id','=', 'table2.user_id')
          ->join('table3','table1.user_id','=', 'table3.user_id')
          ->join('table4','table1.user_id','=', 'table4.user_id')
          ->select('table1.*','table2.email','table3.*','table4.*')
          ->get();

i got the repeated data from the last table alone and also i couldn't get the data from first three tables

I need an output like this

--------------------------------
id      email           user_id
--------------------------------
1       [email protected]    40
2       [email protected]    40
1       [email protected]    40
2       [email protected]    40
1       [email protected]    40
2       [email protected]    40
1       [email protected]    40
2       [email protected]    40
--------------------------------
0

There are 0 answers