Laravel Architectural Decision For Ambiguous Query

The application I’m building requires a query that includes several joins, aggregation and calculated columns The result set of the query itself doesn’t really represent a single table but is mostly calculations using aggregate functions. Being so it does not really fit into something that can be created using Eloquent models. I essentially need to run this query, fetch the raw data than load models as I need them based on the result set. In Doctrine this type of query would fit best in a Repository but that is not an option using the ActiveRecord pattern. So I’m torn as to what would be the best location to place this logic. I’m thinking a separate service independent of my models directory and/or classes. Does this sound like the right approach or should I place it in a static method of a Eloquent model class that already exists?

Hey oddz, what did you decide to do in the end? I’d probably go with a separate class, as it sounds like some kind of report that you’re generating?

Nothing yet, working on other things. Though I have read a couple articles that cite the *best methods are using a command bus or repository layer dependent on whether the action/method needs to return a value or not. The process is actually not a report. It is data entry for an entity that is being abstracted into several normalized tables. There is a single form for this entity and when saved there are close to seven models that are indirectly created that make up the single domain level entity. I was actually thinking since this action is so closely tied to a request to add actions to my custom request class that handle the persist action. At least that way I get all the logic out of the controller actions for now and can further refactor later. Probably a little difficult to understand since I’m speaking in generics but here yeah.

Here is one of the articles I’;m referring to about using a repository layer.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.