Nested Relationships Query

Posted 5 months ago by n-other


I'm having hard time to build proper eloquent query for the following models chain and their relationships:

very short table representation:

users (user_id);

apps (id, user_id);

fees (id, app_id);

purchases (id, fee_id, payment_id);

payments (id);

refunds (id, payment_id);

relations: 1-M apps.user_id; 1-M fees.app_id; 1-M purchases.fee_id;

purchases.payment_id 1-1; 1-1 refunds.payment_id

Proper relationships are set on all Models.

I need to query all refunds by using eloquent relations where user_id = 1. How do I do that?

So far, I was able to build following 1st level query:

      $p = \App\Models\Refunds::with('payment')->whereHas('payment', function($query) {
          $query->where('' => '70');

However, I don't understand how do I go deeper via relations properly.

Please sign in or create an account to participate in this conversation.