Код: Выделить всё
public function index(Request $request)
{
$begin_date = $request->get('begin_date') ? date('Y-m-d 00:00:00', strtotime($request->get('begin_date'))) : now()->startOfMonth();
$end_date = $request->get('end_date') ? date('Y-m-d 23:59:59', strtotime($request->get('end_date'))) : now()->endOfMonth();
$begin_time = strtotime($begin_date);
$end_time = strtotime($end_date);
$a_recharges = ARecharge::select('publisher_id as user_id', DB::raw('SUM(ticket) as coins'))
->whereBetween('created_at', [$begin_date, $end_date])
->groupBy('publisher_id');
$b_recharges = BRecharge::select('user_id', DB::raw('SUM(diamonds) as coins'))
->whereBetween('create_time', [$begin_time, $end_time])
->groupBy('user_id');
$recharges = $a_recharges->union($b_recharges)
->orderByDesc('coins')
->paginate(10)
->appends($request->except('page'));
return view('admin.publisherrecharges.index', compact('recharges'));
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... lumn-names