My model structure is as follows:
Question
hasMany Decision
hasMany Impact
morphTo Related
So I’m trying to get a list of Questions
with all of their Related
objects deep inside.
Example:
{'question':1, relateds:[obj, obj, obj]}
{'question':2, relateds:[obj, obj, obj]}
{'question':3, relateds:[obj, obj, obj]}
I tried hasManyThrought relation, but it only works with two deep levels.
How can I achieve it?
2
Answers
Try
or Something like
Didn’t test.
Edit
or
There is a package for this: https://laravel-news.com/hasmanydeep-package
example usage: Country → hasMany → User → hasMany → Post → hasMany → Comment
Haven’t tested it though