I have been trying to a query where in I want to do some validation on the related tables. I would like to do something like this using Laravel 5
select * from table1 INNER JOIN table3 on(table1.id = table3.table1_id) INNER JOIN table2 on(table1.id = table2.table1_id) where table2.column2 in ('arr1', 'arr2')
Also table1 is related to 5 - 7 tables and I want to eager load all of this. Here's what I had so far
$reports = Table1::with(
[
'table3',
'table4',
'table5.table6',
'table7',
'table8',
])
->where('created_at', '>=', date('Y-m-d', strtotime($request->get('from'))))
->where('created_at', '<', date('Y-m-d', strtotime($request->get('to'))))
->with('table2',function($query) use($table1_column){
return $query->whereIn('table1_column',$table1_column);
});
But this displays everything. Even the items that does not exist in table2. What I would like to achieve is to create a result where all items is the only items that exists in table2. Meaning all transaction made using items in table2. Assuming the item in table2 has an ids of 123, 456, and 789 then I would like to display all record related to this id's
How can I make this kind of result
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire