Answer the question
In order to leave comments, you need to log in
Is it possible to eager load a pivot table?
There are two models, User and Car. There is a linking table car_user, which contains additional fields of type location_id. Now the name of the location is obtained through $car->pivot->location->name (the $cars array is $user->cars), but it is not possible to make a greedy request using eloquent to get all locations, so a lot of requests are created when accessing location. How to implement eager loading in this pivot and has anyone done it?
Answer the question
In order to leave comments, you need to log in
On the Laravel forum, they suggest creating a regular model for pivot tables and linking all three models to each other with the necessary types of links, and then eager loading between them. Something like this)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question