Примите это как ссылку.
$sub_query = DB::table('orders as o')
->leftJoin('meals as m','m.id','=','o.meal_id')
->where('o.shift_id','=',1)
->where('o.meal_id','=',2)
->where('o.city_id','=',283)
->where('o.restaurant_id', '=', 5)
->select(DB::raw('COUNT(*) AS per_hub,CEIL(COUNT(*) * 50 / 100) AS additionl_qty,m.cost_price'))
->groupBy('hub_id');
$main_query = DB::table( DB::raw("({$sub_query->toSql()}) as records") )
->select(DB::raw('SUM(records.per_hub)+SUM(records.additionl_qty) AS qty,
records.cost_price,
(records.cost_price)*(SUM(records.per_hub)+SUM(records.additionl_qty)) AS total'))
->get();