Dealing with the n+1 problem in Laravel

preview_player
Показать описание
Dealing with the n+1 problem in Laravel by using the $with model attribute and the newly added Model::preventLazyLoading() method.
Рекомендации по теме
Комментарии
Автор

A bit of warning to those thinking that the "with" model property is the solution to all N+1 problems: enabling it on all models can quickly lead to recursion, and debugging nightmare. This aspect deserves significant consideration when planing out your architecture and use of the "with" property. For this reason I have avoided using the model property, and instead used with explicitly on eloquent queries. That also helps keep the payloads small, if you end up using the model in Livewire.

mischl
Автор

Greate video. We need more videos like that. More Laravel tips. Thx a lot

MateusGalasso
Автор

First time here and subscribe in a few seconds of video :) . Please do more tips and tricks. Thanks

luzaw
Автор

Neat indeed, thanks!
One suggestion: maybe consider a slightly larger font next time (for both the browser as well as phpstorm)

mc-tybr
Автор

You stated the argument that "we might forget to add eager loading using 'with' in eloquent query and that's why it's a good idea to use the 'with' attribute in the Model". But then it will cause more problems because every time it'll try to load all the relations defined in the model attribute. To solve it we need to use 'without' or 'withOnly' in the eloquent query. Aren't we back at where we started? Isn't it easy to forget about 'withOnly' and 'without' too? I believe that we are bloating the framework with many unnecessary features and trying to do everything inside the framework when these should be carefully done by the developers themselves.

ahmed.shamim
Автор

This is cool. I wonder if you could automaticlly add the eager load by default when it is omitted?

NathanBudd
Автор

Hey Bro.... 1 help needed

Awesome video. Just 1 more information I need for this,
If i do use relation, I don't want to pull all columns from my 2nd table. How can I do it ? I hope you understood my question. Please do reply

marthasteve
Автор

Is this channel yours or you have other personal channel?!

EL_PANDA_
Автор

Why wouldn't eloquent use a join here and do it in one query?

twiggy
Автор

thats great but can you enable comments on your laravel vapor videos on this channel? why have you disabled the comments anyway?

Peter-ueiz