I have the models "Payment", "Estimate" and "Quote", a payment has a polymorphic relationship where it can belong either to a quote or to an estimate, simultaneously a quote can have many estimates, so an estimate is always going to belong to a quote.
Basically, all payments are always going to belong to a quote, sometimes directly and sometimes through an estimate:
quotes:
id
estimates:
id
quote_id
payments:
id
paymentable_id
paymentable_type ("App\Models\Quote" or "App\Models\Estimate")
My question is, how can I define the relationships so when I use $quote->payments
, it would not only return the payments that are directly related to the quote but also the payments that are related to the estimates that belong to that quote.
Any suggestions? Thanks in advance.