TL;DR
ORM sits better on the Model
This question is relative to PHP - Laravel, but really, it's a problem or any software that follows the MVC design.
Laravel, is a quite opinioned Framework and the structure that it has by default is just better be followed, however it follows very well the MVC design.
Now, from the mdn docs above
- Model: Manages data and business logic.
- View: Handles layout and display.
- Controller: Routes commands to the model and view parts.
Already from this, we can understand that, the best place is the Model.
Now, why does Laravel says that "ORM calls are fine in the Controller"?
My guess is because, to be more flexible for the users and for easier explanation on the documentation, Laravel is a great framework which is used by both experience and beginners (or comanies that don't work very well) so the documentation is very user friendly.
I saw companies putting more business logic on the controllers and models are simple opaque
Classes, using a combinations of DTO - Data transfer object and Domain Models and combinations of these:
I also saw companies where, the Model, is used as simple DTO (or call it whatever, just a class with no logic where has only fields that matches the sql table)!
Now, using a ORM, changes a bit the game, since, is a combination of the above plus, makes you able to perform sql queries on a Object Oriented approach.
You could decouple the Model from your actual ORM implementation as is suggest in here In MVC, does an ORM represent the model?:
ideally you'd want to decouple the shape of the Domain Model classes from the shape of the database tables.
However, putting on the Model, could be a good start, but on the Controller is a bad practice
In here, how to structure MVC models and ORM models, is quite interesting since they are talking about Entities which are DTO but with a cooler name.
Related