Description
Laravel Version
12.9.0
PHP Version
8.3.8
Database Driver & Version
MySQL 8.4
Description
Global Model::automaticallyEagerLoadRelationships
doesn't work for BelongsToMany because it has its own get
method which does not take into account this functionality.
And if you use Model::preventLazyLoading
you get LazyLoadingViolationException
.
Steps To Reproduce
Model::automaticallyEagerLoadRelationships();
Model::preventLazyLoading();
// contracts is BelongsToMany relation
$contracts = $project->contracts()->get();
foreach ($contracts as $contract) {
// LazyLoadingViolationException here
$contractors[] = $contract->contractor;
}