Como puedo pasar la siguiente consulta anidada a laravel con Eloquent?
select AVG(total_puntos)
FROM
(
SELECT uca.user_id, SUM(uca.points_user) as total_puntos
from user_category_activity as uca
join client_user as cu on cu.user_id = uca.user_id
where cu.client_id = 3
GROUP BY uca.user_id
) as promedio_total
Hasta el momento tengo esto (consulta interna), me hace falta el promedio:
$sumapuntos=DB::table('user_category_activity as uca')
->select(DB::raw('uca.user_id, sum(uca.points_user) as points_user'))
->join('client_user as cu', 'cu.user_id', '=', 'uca.user_id')
->where('cu.client_id', $c->client_id)
->groupBy('uca.user_id')
->get();