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

kaushal's avatar

For select query which is better eloquent query or db query? and why?

For select query which is better eloquent query or db query? and why?

0 likes
2 replies
MichalOravec's avatar

Actually it doesn't matter in most cases. For example

DB::table('users')->where('name', 'John')->first();

is same as

User::where('name', 'John')->first();

With Query builder you usually use joins and with Eloquent relationships. But with Eloquent you can use joins as well. I prefer to use Eloquent.

jlrdw's avatar

There's a bunch of personal preference when it comes to that. I use getPdo (), and of course bind my parameters.

Though I use eloquent for some things.

I stay away from collections, they are so neat when dealing with a few hundred or even two or three thousand records, but you let your database go into the million's, well you don't want millions of Records in an array.

Please or to participate in this conversation.