Using the CROSS JOIN subquery
1use Illuminate\Support\Facades\DB;2 3$totalQuery = DB::table('orders')->selectRaw('SUM(price) as total');4 5DB::table('orders')6 ->select('*')7 ->crossJoinSub($totalQuery, 'overall')8 ->selectRaw('(price / overall.total) * 100 AS percent_of_total')9 ->get();
Tip given by @PascalBaljet