Member-only story

Laravel: How to move FAT logic to the Model layer

Luís Nóbrega
6 min readApr 26, 2020

--

Why we should avoid FAT Controllers, and how to structure the Model layer in Laravel.

Photo by Luca Bravo on Unsplash

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?

Photo by Patryk Grądys on Unsplash

What controllers typically do?

They receive requests and return responses, having, in general, the following responsibilities:

--

--

Luís Nóbrega
Luís Nóbrega

Written by Luís Nóbrega

Web Developer at 25friday. Likes to travel, write and being a father.

Responses (1)