1In addition to @delmadord's answer and your comments:
2
3Currently there is no method to create subquery in FROM clause, so you need to manually use raw statement, then, if necessary, you will merge all the bindings:
4
5$sub = Abc::where(..)->groupBy(..); // Eloquent Builder instance
6
7$count = DB::table( DB::raw("({$sub->toSql()}) as sub") )
8 ->mergeBindings($sub->getQuery()) // you need to get underlying Query Builder
9 ->count();
10Mind that you need to merge bindings in correct order. If you have other bound clauses, you must put them after mergeBindings:
11
12$count = DB::table( DB::raw("({$sub->toSql()}) as sub") )
13
14 // ->where(..) wrong
15
16 ->mergeBindings($sub->getQuery()) // you need to get underlying Query Builder
17
18 // ->where(..) correct
19
20 ->count();