Sunday, February 11, 2018

Laravel 5.5 – Return hasMany results from another hasMany - development

Laravel 5.5 – Return hasMany results from another hasMany

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?



from Laravel Questions and Answers https://laravelquestions.com/laravel/laravel-5-5-return-hasmany-results-from-another-hasmany/
via Lzo Media

No comments:

Post a Comment