'Laravel Eloquent Errors

Hi everyone how are you all, i have some issues with PHP and Laravel exactly in Eloquent Laravel. My Questions is how can i convert this SQL what i have made in phpmyadmin to laravel ELoquent, whit not errors cause i have got a lot of erros trying to get the solution.

SELECT users.registrante, users.id,  Sum(1) AS Cant
FROM users
GROUP BY users.registrante
ORDER BY SUM(1) DESC;

it works in phpmyadmin, but i have no idea how can i convert to laravel.

first error

$historial = User::select('users.id, users.registrante')
    ->orderBy('sum(1)','DESC') 
    ->groupBy ('users.registrante') 
    ->get();

the message from this error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.id, users.registrante' in 'field list'

Hi and i hope you can help me with this :)



Solution 1:[1]

Forget it guys, i got it it work with this code

$historial = User::groupBy('registrante')

->selectRaw('sum(1) as sum, registrante') ->get(); //this return collection

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Moises Leandro Gonzalez Diaz