$rating = User::query()
->join('championship_sessions', 'users.id', '=', 'championship_sessions.user_id')
->whereBetween('championship_sessions.created_at', [
$activeChampionship['data']['start_time'],
$activeChampionship['data']['end_time'],
])
->where('championship_sessions.status', '=', 1)
->groupBy('users.id')
->orderBy('users.rating', 'desc')
->select(['users.id', 'users.name', DB::raw('COUNT(championship_sessions.status) as rating'), 'users.status_name', 'users.status_id'])
->paginate(100)->toArray();
$users= User::query()
->where('users.ban', '!=', 1)
->where('users.rights', '=', 1)
->leftJoin('users as referal', 'users.id', '=', 'referal.ref_id')
->whereNotNull('referal.id')
->select([
'users.id',
'users.name',
'users.telegram_id',
DB::raw('count(referal.id) as total_referal'),
])
->groupBy('users.id')
->orderByDesc('total_referal')->paginate(100);