Member-only story
Laravel: How to move FAT logic to the Model layer
Why we should avoid FAT Controllers, and how to structure the Model layer in Laravel.
Laravel is one of the MVC frameworks from the PHP ecosystem.
And, as such, when we use it, the M and C, models and controllers, have a lot of code.
This makes sense because we need these layers to do the vastest and different operations.
No problem.
The problem happens when we have a lot of code and responsibilities in one of the layers. This can harm our codebase.
Bloating anything is always an anti-pattern. Separation of concerns helps maintenance and testing.
But when we say, skinny controllers, fat models, we mean that the model is a layer and not only a class. Having a god model is bad also.
Let’s see how can we structure our code in a Laravel application.
Why skinny controllers?
What controllers typically do?
They receive requests and return responses, having, in general, the following responsibilities: