i'm learning about repository pattern and i have seen a lot of examples where repository pattern is used for creation and update. Here is one example of repisotory interface.
interface RepositoryInterface
{
public function all();
public function create(array $data);
public function update(array $data, $id);
public function delete($id);
public function show($id);
}
This repository interface is responsible for creating/retrieving and updating models.
But then, after a little better search, i found that people should avoid to persist data in repository and that repositories should act as collections and be used only for retrieving data. Here is the link .
Here is what they say there.
Probably the most important distinction about repositories is that they represent collections of entities. They do not represent database storage or caching or any number of technical concerns. Repositories represent collections. How you hold those collections is simply an implementation detail.
Here is one example of repository that only retrieve data.
interface BlogRepositoryInterface
{
public function all();
public function getByUser(User $user);
}
I am wondering what is the best practice for repository pattern?
If we should use repository only for retrieving models, how then we handle create/update/delete models ?
Aucun commentaire:
Enregistrer un commentaire