Say I have a model that morphs a number of different models (using morphTo). I'm trying to achieve that whenever a model is morphed, all (or some) relations on that morphed model are eager loaded too.
Example code here: http://laravel.io/bin/yLyz7
Whenever I'd call:
Index::with('item')->get();
It will eventually result in a query like so for the morph:
SELECT * FROM sample_items WHERE id IN (?, ?, ?)
This is exactly what I want, but I also want to eager load any relations on the SampleItem models, so that instead of querying the relation for each SampleItem every time, it would also create a query like this. Assuming SampleItem has a "user" relation.
SELECT * FROM users WHERE id IN (?, ?, ?)
Is there any way to achieve this? Because I'm not calling the SampleItem model myself, I can't specify any eager loaded relations. I assume I'd have to specify this in the relation on Index, but I can't figure out how. I'm not sure this is even currently possible.