DEV Community

Discussion on: Handling complex MVC applications - How to scale and avoid Controller chaos

Collapse
 
pavlosisaris profile image
Paul Isaris

Thanks for your comment Dmitry. ORM is indeed very handy (and Laravel's Eloquent is very powerful), but you need to know how to use it, or which of it's features will obstruct your app's scalability.

Collapse
 
alexeevdv profile image
Dmitry Alekseev

My point is that if you go with layers then all ORM stuff should end up in persistence layer. Your controllers and business logic should know nothing about ORM

Thread Thread
 
pavlosisaris profile image
Paul Isaris

Hmm I get what you are saying. Do you mean that I shouldn't refer to DB table fields (like author_id) in the business logic layer?

Thread Thread
 
alexeevdv profile image
Dmitry Alekseev

More than that. You should not even have access to the database on the business logic layer. It should be done in persistence. With your current approach you pass ORM models into the view level where everyone will have direct access to the database because of access to ORM model. Somebody can make something like $model->delete() in the view template and mess the things up.

To prevent it you need to decouple persistence level and all other levels. In the persistence level itself you are free to use Eloquent, Doctrine, raw SQL queries, etc...

For more information please refer to fideloper.com/how-we-code