I am implementing Repository Pattern in a large scale laravel app. I have put almost all sophisticated and reusable database logic in these model repositories and i feel its helpful and more organised. All the entity creations, retrieval etc code live in these repositories now.
But my confusion is: what should I do with the custom eloquent methods, for example I have a model with methods such as $model->canPerformXTask()
, $model->isActive()
, $model->hasTooltip()
etc.
There are instances where I just want to use these methods to perform some logic in controllers or services. What should I do with these if I am implementing Repository Pattern ?
- Should I create these methods inside ModelRepository?
- Is it okay to have db logic in repositories but also use the eloquent models outside of it ?
- Does having a repository pattern means "use eloquent models within the repositories only?"
Any insight on this will be very helpful...
find
method, returning the Model with a given id? You can use$this->repository->find($id)->isActive()
, or$this->repository->find($id)->hasTooltip()
– Mateus Junges