What is a Single Action Controller?
It is a Controller dedicated to a single action.
For example:
Instead of creating a single UserController
for all CRUD actions as methods and some additional, like filters and showing, you are creating a Controller for each action, which becomes CreateUserController
, GetUserController
, FilterUserController
and so on.
Source: Single Action Controller in Laravel
Pros
✅ has one job only
✅ has a descriptive name, and it’s easy to understand what it does
✅ is easy to change
What are the cons for Single Action Controllers?
I've read some articles and the only cons I've found is that you'll end up with “tons of controllers over time”. The author says that it's not a good idea if you’re aiming for scalability in terms of development.
Cons solution
In fact, you can wrap controllers in folders by modules. By putting all user controllers under User
folder, you end up having a clean hierarchy of controllers sorted by modules and a bunch of Pros in addition that are making the architecture easy to maintain.
What do you think about it?
Top comments (0)