Question Details

No question body available.

Tags

laravel

Answers (1)

April 3, 2026 Score: 0 Rep: 40,994 Quality: Medium Completeness: 60%

You are right to say that using Eloquent makes using a repository redundant IMO because eloquent implements the Active Record pattern which is generally considered an alternative to the Repository pattern. You can still implement the repository pattern if you choose but I find that usually unnecessary.

The code you shared would also not really fit into any of these patterns though because it is more than just a database operation, doing a groupBy after the get means that you are doing post-processing on results after you got them so this would typically happen outside a repository or active record as it is not part of your database query.

The complexity of this particular code seems low so it can realistically be part of the controller action, however more complex operations are typically performed in a separate class. I don't know how you would choose to refer to this, some people call these Services and others call these "Business Logic" classes but overall this is where this sort of logic could end up in.