Design pattern for fetching associated entities

by musicliftsme   Last Updated October 12, 2018 14:05 PM

I have a User model which has "Payments" in quotes because depending on the user, there could be multiple sources of payments, like StripePayments or BraintreePayments. Instead of writing all the business logic inside the User model via something like a getPayment() method, I'd like to delegate it out to another layer. The business logic entails retrieving only, and the retrieved data could be of a single payment source or mixed.

At my company, "repositories" have been used for this kind of stuff, but I feel the pattern is misused, and I'd like to know if there's another suitable pattern. This is something I would've traditionally put into the service layer or even a helper, if I couldn't find a place for it.

Any suggestions on this? I'm using PHP and Laravel for this.



Related Questions


Is it good to pass the variables through methods?

Updated March 13, 2017 12:05 PM