The code below is not working.
$subQuery = DB::table('table1')->groupBy('col');
$data = DB::table($subQuery, 'sub')->get();
Can you help me with this?
The code below is not working.
$subQuery = DB::table('table1')->groupBy('col');
$data = DB::table($subQuery, 'sub')->get();
Can you help me with this?
Your code is already functional. The only alternative (to make the same query) is to inline the $subQuery part.
$subQuery = DB::table('table1')->groupBy('col');
$data = DB::table($subQuery, 'sub')->get();
Is the same as
$data = DB::table(function ($sub) {
$sub->from('table1')
->groupBy('col');
}, 'sub')
->get();
or
$data = DB::table(DB::table('table1')->groupBy('col'), 'sub')->get();