until now I have managed to count the children of each parent, that is to say, with the following method I achieve the following result.
public function reportes(Request $request)
{
$request->user()->authorizeRoles(['admin']);
$reporuser=usuarios::distinct('usuario_ad')->pluck('usuario_ad');
foreach($reporuser as $reporuser)
{
$conteo=usuarios::where('usuario_ad',$reporuser)->count();
echo $conteo
}
}
the result is 4233, so a parent user has 4 children, another 2, and the last two parents have 3 users, the expected result, but when I replace echo by return it only shows me the first value, I mean 4 , and I do not know why.