$dataTempQuery = $dispatchCostPay->groupBy('costs.ID')->union($orderCostPay->groupBy('costs.ID')); $data = \DB::table(\DB::raw("({$dataTempQuery->toSql()}) as t"))->groupBy('ID')->skip($skip)->limit($pagesize)->get();