N
N
nepster-web2016-11-28 11:19:47
Laravel
nepster-web, 2016-11-28 11:19:47

Repository and ActiveRecord, is it a good idea to return models?

I developed it on laravel5 for several months and realized that I messed up with the repositories, or rather, I got about 0 efficiency. Now I'm trying to figure out how to fix this whole thing and find out the opinions of different specialists.
When I surfed the Internet, I found various applications where they messed up about the same as me. Here is an example of such an application:
https://github.com/Bottelet/Flarepoint-crm/
Repository:
https://github.com/Bottelet/Flarepoint-crm/blob/de...
Actually, what are the problems here:
- logic in the repository
- duplicate request in the update method (we pass $id from the model to get the model). In my application, I screwed up even more harshly, as I also passed the model to get rid of this request.
- single responsibility violation (bcrypt)
- returning the model as a result from the repository.
That is, if you use repositories as really repositories and replace, say, a model request with a request using a query builder, and one fine day, not a model, but a collection will return from the repository, this does not guarantee any stable operation of the application.
From here the question is, why are there repositories, if this is an abstract storage over models, and not an abstract storage in general?
Well, the main question is, am I forming thoughts in the right direction, and how can a similar approach with repositories be implemented correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Plisko, 2016-11-28
@nepster-web

This is a typical example when people don't get to the patterns themselves, but read smart books and stick their repositories and ddd without a clue why it's needed.
How many articles have already seen about using repositories in laravel, all offer Model::all() kuegkt, etc. It doesn't matter that they return the same Eloquent that they are trying to remove.
In symfony projects, even with doctrine, the same hell is going on. That. that people do not know how to make normal repositories indicates that they did not need such an abstraction. For 99% of projects, you shouldn't drag abstractions like repositories at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question