Eager loading eloquent model relationships falls back to lazy loading.
- Dominant language
- PHP
- Stars
- 9.4k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
I have an Eloquent model that has several relationships to other models, some of which have nested relationships themselves.
Eager loading theses relationships from within Eloquent at getting a collection containing the loaded data seems pretty straight forward.
However when I use this collection with Dingo's response()->collection($collection, $transformer) the eager loaded data is ignored and it falls back to lazy load everything.
```
$collection = Model::query()->with('relation', 'relation.nested')->get();
$response = $this->response()->collection($collection, $transformer);
```
The transform method is like:
```
public function transform(Model $model) { return ['nested' => $model->relation()->first()->nested]; }
```
Should that in principle already use eager loading or do I **have** to use Fractals $defaultIncludes = ['relation']; and includeRelation() mechanism like here?
[http://fractal.thephpleague.com/transformers/](url)
Contributor guide
Assessment
This issue has not been assessed yet.