Models out of control

We use laravel in our company and we follow two simple conventions:

  • Controllers should be thin.
  • Models represent database objects (user, roles, cars)

Now we are faced with a dilemma: we have a screen that presents complex data graphs that require long and heavy logic. But where should we put all this logic? controllers should be thin - therefore not in controllers. Models are data entities, so a model cannot be a model as this screen displays data from all other models, but they do not have an actual table / database object. The services don't sound like a normal place.

I was wondering how you treated such situations.

+3


source to share


1 answer


I would include logic. In a service, you can start other services (in case some logic is already in another service or if the service is very complex) and use repositories (or models in case you are not using any repositories). Of course, it doesn't make sense to put a lot of code or logic in controllers, because they can start services that return the desired result.



0


source







All Articles