DEV Community

Discussion on: Does repository pattern make sense when using it in Laravel?

Collapse
 
eduardort profile image
Eduardo Reyes

The repository pattern and Eloquent are not competitors, you can use Eloquent inside a repository, it's particularly useful when you need more functionality that makes the Eloquent Query weird, it can also make your code more legible with stuff like getAdmins or getActiveUsers instead of the direct query – also, having the query in one place instead of multiple will allow you to reduce errors

If you don't need to re-use the queries then a Repository is overkill anyway – Even though, it can still provide value depending on the complexity of the queries.

I've seen it used in Laravel apps before, in conjunction with the Service Pattern, this was a massive codebase though.

YAGNI and KISS always in mind!