0
votes

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...

1
Does your repository have a 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

1 Answers

1
votes

I think it's more an opinion answer for everyone, and the debate will never end on this topic.

But, there's an expert answer by Povilas Korop on his youtube channel "Laravel Dialy" where he talks about this topic. you can find it with

"Laravel Code Review: Why NOT Use Repository Pattern?"