Why aren't you using the relationships? Follow this: https://laravel.com/docs/5.8/eloquent-relationships
Jun 30, 2019
3
Level 1
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.
Level 18
Please or to participate in this conversation.