Reputation: 12598
I am getting all memberships in a Laravel 5.5 API route like this...
$membership= Membership::with('user')->findOrFail($id);
return Response::json(array(
'error' => false,
'user_data' => $membership,
));
I have a Membership hasMany Users relationship setup so this correctly returns all users belonging to this membership.
I also have a Users hasMany Images relationship setup, is there a way I can also return a list of all images that belong to the returned users?
Should I be creating a seperate function that compiles a list or can it be done directly from the with statement?
Upvotes: 0
Views: 49
Reputation: 3543
If by Subscription
you meant Membership
then the code below should work
$membership= Membership::with('user.images')->findOrFail($id);
Upvotes: 1
Reputation: 7489
Try this, No need for extra relation load
$membership= Membership::with( 'user.images')->findOrFail($id);
//get users of this membership with their images
Upvotes: 1