Dont hate me if I missed something, I skimmed your code, and I think I know what you are looking for.
Nested Relationships:
User::with('userable', 'userable.articles')->find(1);
I'm not sure if the first userable
is required.
But Laravel uses dot-notation for lots of nested things. This applies to relationships & nested relationships.
Mh interesting.
Okay with the following
$user = User::with('userable')->find(1);
im getting the users properties as well as the userable properties, which is great. The dot notation isnt working at all, the results are not different from the call above.
When i now try to do the following, im getting again very confusing results:
$user::with("articles")->get();
This results in an array of user objects, with the userable properties AND the articles. So in fact its exactly what i was looking for, BUT the problem is im not getting the expected results ONLY for the earlier created $user with the id 1..its an array of 2 user objects, because currently im having 2 test users in my database.
The only way to achieve what im looking for is setting the $with property directly in the users model, but then im eager loading all this stuff every time im using my user model, which can't be the right way :(.
http://www.laravelsd.com/share/NE3uzq
This is what i've got. What i want to achieve: Having a user id, i want a complete object of the user, its userable properties, all articles with the media and its mediable properties. How can i achieve this?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community