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

daniel21gt's avatar

convert sql query

Quiero convertir una consulta sql en formato eloquent

select * from usuarios where usuario_ad = "danielad";

to

Usuarios::where("usuario_ad","=",'danielad');

But in eloquent it does not work I just receive this,

Illuminate\Database\Eloquent\Builder {#2892}

How could the correct translation of this query be in eloquent?

0 likes
2 replies
matttonks11's avatar
Level 7

Hi, there's nothing wrong with your query you just need to add ->first() or ->get() on the end to actually get the data like so...

//gets the first user where usuario_ad is danielad
Usuarios::where("usuario_ad","=",'danielad')->first();

//get all the records where usuario_ad  is danielad
Usuarios::where("usuario_ad","=",'danielad')->get();

1 like

Please or to participate in this conversation.