In our legacy admin we noticed a lot of lazy loaded media relations that causes an n+1 issue silently without throwing an exception even with Model::preventLazyLoading() enabled globally.
The related issue referenced above gives more details.
Changes
Add new config parameter force_lazy_loading to allow enable/disable media lazy loading. Enabled by default, so it will not require any changes for those happy with the current behavior.
Update the InteractsWithMedia trait to load media based on force_lazy_loading value.
Update the docs to show the new config parameter.
Add new test to check that media still lazy loaded even with Model::preventLazyLoading() enabled globally, but force_lazy_loading still on it's default value.
Add new test to check that it throws a LazyLoadingViolationException exception when Model::preventLazyLoading() enabled globally and force_lazy_loading set to true.
References
Related issue: https://github.com/spatie/laravel-medialibrary/issues/3554
Story
In our legacy admin we noticed a lot of lazy loaded media relations that causes an n+1 issue silently without throwing an exception even with
Model::preventLazyLoading()
enabled globally.The related issue referenced above gives more details.
Changes
force_lazy_loading
to allow enable/disable media lazy loading. Enabled by default, so it will not require any changes for those happy with the current behavior.InteractsWithMedia
trait to load media based onforce_lazy_loading
value.Model::preventLazyLoading()
enabled globally, butforce_lazy_loading
still on it's default value.LazyLoadingViolationException
exception whenModel::preventLazyLoading()
enabled globally andforce_lazy_loading
set totrue
.