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

codex.jo's avatar

Which is better to use Eloquent ORM or Query Builder ?

Hi , everyone !

We have a big database and we will refactor our project to support RESTFul APIs , so we need to know which approxh is best .

when we choice Eloquent ORM we know it have a performance issue , by the way with ORM we write a clenable and readable .

but when we choice Query Builder we know it's a good choice for performance but we don't write a cleanable code .

So Whice is best ?

0 likes
2 replies
eterlinden's avatar
Level 14

Hey @codex.jo ,

I've been working with Laravel for about 7 years now, and I'll give you my thoughts on the question. Fundamentally, I stick to using Eloquent whenever possible, and only grab for the Query Builder when the situation/need is more easily handled with it, or cannot be fully replicated with Eloquent.

Eloquent is a fantastic Active Record implementation and ORM, which makes every day tasks a breeze to accomplish, seeing that there is no direct writing of any SQL involved.

Yet, sometimes you want to do something fairly complex and want to work out the fundamental logic details first. That's a good time to grab for the Query Builder, since it is more directly relatable to vanilla SQL syntax.

Conclusion - it's good to know both well in, in order to be able to assess when to use them.

Hope this helps you a bit.

Cheers.

2 likes
SilenceBringer's avatar

@codex.jo Eloquent forwards a lot of methods to Query Builder, so in total you have almost the same performance for queries with simple where statements.

Eloquent have performance penalties for relationship existance checks like has and whereHas, but it's still ok for most cases (unless you develop really big application)

Anyway - no one force you to use it, and you still can do the same using joins, called on eloquent model.

So, my answer is - use Eloquent (which effectively will just forwards methods to Query Builder in most cases) unless you develop enterprise-level application.

Please or to participate in this conversation.