Eloquent or Query Builder: When to Use Which?

preview_player
Показать описание
I've been asked this question quite a lot, so decided to discuss the pros and cons of each approach.

My course "Eloquent: Expert Level"

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

One thing you missed is that when you use query builder you don't get advantages of model events

SacredHeartsCoc
Автор

Exactly as you say! I am using eloquent mainly and query builder for specific things. The beauty of Laravel: various tools, you can use the best out of both worlds!

flying_david
Автор

Love your videos. Small bite size chunks and very informative!. Thanks.

olixz
Автор

I think as a back end developer what is matter is performance and when u are good enough in sql writing queries is a piece of cake . Thanks for this video it is really helpful

generalcoder
Автор

It is unreal that you managed to hook me into your QAP, but I have to say... I adore your content and I adore your services. Much obliged

oliverkobing
Автор

Thank You. I'm getting answers for my questions.
Ha suffered a lot with Eloquent - at the end i managed to solve it that i prepared a view in MySQL and joined this with raw query. I needed sums, with group by with 2 additional joined tables.

GergelyCsermely
Автор

you just made things clearer for me when trying to understand this awesome framework, thanks boss

IglesiaNuevaJerusalen-lkvi
Автор

I use both for Eloquent and Query Builder. Thanks for this info

mackynyxz
Автор

I think it all depends on the case, but for the most part for general use it is better eloquent.

abelenocrodriguez
Автор

Recien llego al canal por una duda puntual y el video me encanto!! Ya me suscribi para seguir aprovechando siempre la info que venga de gente mas experimentada

yamila
Автор

Excellent advice! Thanks for the hard work.

elilopezdev
Автор

Awesome tutorial as always. Keep it up👍👍👍👍

gautammenariya
Автор

Thank you, great content as always. My experience:
1. Simple INSERTS: Eloquent
2. Complex INSERTS: Query Builder
3. Simple READS : Eloquent
4. Complex READS : Query Builder
5. Very Complex READS : Raw SQL

What i miss out for not using eloquent fully is eloquent convenience/magic such as model events. I also find myself not using Eloquent Relationships.

josephnduati
Автор

Thank you for useful video Povilas. Just right now I'm testing a database having 500k+ products with many relations and time loses for eloquent queries are noticeable.

denyart
Автор

I normally use Eloquent. But when I do charts, reports, export and etc, query builder rules.

tiagooliveira
Автор

Thanks! Never thought about that difference.

modestusmunh
Автор

I've had many situations, where I have had to switch to DB facade. More complicated queries usually tend to be much slower in Eloquent than using the facade or doing raw queries. Eloqent is programmer-friendly.

oliverkobing
Автор

Well, in my case, I like to use Raw Queries. Correct me if I'm wrong, but nothing can be more performative than Raw Queries, because I think there are almost no layers betweeen Laravel em PHP PDO/MySQLi/whatever.
Of course the table changing name is more effective with tradicional model approach, but you can always refactor you code with your editor. For me is not a big deal.
And one very important downside of using only EloquentORM or Query Builder is that this is not available on the tools you use to manage directly you database on the server (SequelPro, HeidiSQL, PHPMyAdmin, etc.) Therefore, there can be a time when you will forget how to write propor SQL queries because you are used to run them with Query Builder. Just my 5 cents

JLDRPT
Автор

Thanks for your Video, i want a video from you-> about curd operation (edit), actually how to put old value on combo box, using eloquent and db query both

engramiribrahim
Автор

I've used query builder for search data by any column. For me it's faster than scope search. I've tested.

xdEdgarBest