I want to create a Laravel application in which users are both web and part of the API. The general (and my) question is whether to use separate controllers or not.
There are 2 options:
Those who have a first opinion do not explain the solution to the DRY problem - the network and API controllers will be the same except for the return statement (in the form of JSON or HTML). But since most messages recommend sharing controllers, I suspect I donβt understand something about solving the DRY problem.
I do not see the flaws of the second method. But people say something like
If you use only one controller, you will end up with a dirty class with thousands of lines soon. Not only will this not scale well, but it will be difficult to work with you for you and your teammates.
Please explain to me the solution to the DRY problem for the first approach (individual controllers) and possible pitfalls in the second approach (single controller)
Please explain which approach is preferred.
source
share