Answer the question
In order to leave comments, you need to log in
Infer nested relation via one method in Laravel Eloquent Model?
Dear participants of the toaster, we really need help. I will be grateful for any answer.
In general, everything is very simple: there is a user model. Each user is associated with a card. This card has a subscription. Promotions are attached to the subscription, discounts are attached to the promotions.
user->cards->subscription->promotions->
discounts user()->discounts)? Or how it can be optimized.
P.S. The discount cannot be tied to a specific user due to the specifics of the business logic.
Eager Loading I know, but this is a wild chain of passes through arrays in the code. And the method must be used regularly.
Answer the question
In order to leave comments, you need to log in
There are at least two solutions:
1. Write a query yourself, then get a collection of models using the method Illuminate\Database\Eloquent\Builder::hydrate()
+ repository for convenience.
2. Implement your own connection, since in laravel this is easy: it is enough to inherit the class Illuminate\Database\Eloquent\Relations\Relation
and implement all the methods. For example, you can use standard links.
PS There is no way to solve this problem by standard means.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question