laravel-best-practices icon indicating copy to clipboard operation
laravel-best-practices copied to clipboard

Interface best practice

Open jocelinkisenga opened this issue 2 years ago • 5 comments

What about using interface with repository classes?

jocelinkisenga avatar May 06 '22 17:05 jocelinkisenga

My opinion: The repository pattern is the devil and should be avoided. It's taking SOLID to unnecessary levels with an ORM framework. Otherwise just store interfaces in Contracts/

JohnnyWalkerDigital avatar Aug 04 '22 15:08 JohnnyWalkerDigital

but for me, i like using repo than interfaces

jocelinkisenga avatar Aug 11 '22 23:08 jocelinkisenga

We need more than "I like it". In general there is a significant positioning against repositories in Laravel, mainly because it relies in an Active record pattern, and its advantages are lost when Models are isolated in Repos. In terms of Models, Laravel's style mean the use of Concerns to compose behavoir. That means that every functionality should also be exposed explicitly in Repos, what makes things complex.

carlos-mora avatar Aug 12 '22 10:08 carlos-mora

how that things can get complex? give your real example of using repo pattern

jocelinkisenga avatar Sep 17 '22 12:09 jocelinkisenga

Hello everyone,

adding my 2-cent to the discussion about repo patterns:

From working on a larger, aged applications with repos, the repos didn't add much benefit IMHO. The repo pattern seems to work better for frameworks without strong ORM or even completely without any ORM. With Laravel most of the value from repos comes from abstracting a few setters/getters away and being more DRY. The setters and getters are covered with Eloquent pretty good already I think. The DRY part can easily achieved with an actions nicely I would argue. Can you share where you see the advantages @jocelinkisenga?

Cheers, Peter

spekulatius avatar Sep 17 '22 15:09 spekulatius