Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

daniel21gt's avatar

Problem with translation of query to eloquent, laravel 5.5

What a companion.

I have tried to convert this sql query to eloquen, but I have messed it up when joining another query.

select usuario_ad, count(usuario_ad) from usuarios where usuario_ad in (select username from users where users.refer="Thor" union select "Thor") group by (usuario_ad);

in eloquen

$uno = User::where('refer', 'thor')->select('username')->union('thor'); Usuarios::select('usuario_ad')->count('usuario_ad')->whereIn('usuario_ad', $uno)->groupby(usuario_ad);

They are two different tables, one called usuarios and other users.

0 likes
3 replies

Please or to participate in this conversation.