S
S
Stanislav Pochepko2016-07-27 19:14:43
Laravel
Stanislav Pochepko, 2016-07-27 19:14:43

How to properly implement the Repository pattern in Laravel?

Hello. I decided to join the beautiful and try the "Repository" pattern.
And I have some thoughts on using it, but it needs someone to say, "Yes, it is" or "No, you're making up bullshit."
As I understand it, I first create an interface, and then the repository object itself, which implements this interface.
The implementation needs methods to get, create, save models.
In the methods themselves, it will already be possible to configure the availability of the required objects using policies and so on. That is, I have one point in the application where I can access them (or not).
The question is, is it necessary to make a separate repository for each entity / model?
Can there be many different repositories for the same entity? And do they have to implement only one interface or can they be different?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmitriy, 2016-07-28
@dmitriylanets

$Criteria = (new Criteria())
->setWhere('name','test')
->setOrderBy('name');

$users = $userRepository->findAllByCriteria($Criteria);
$user = $userRepository->findById(1);
$user->setName('newname');
$userRepository->save($user);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question