Middleware vs. Controller

Hello,

I’ve got a question regarding what logic to put inside a middleware vs. what logic to put inside a controller?

E.g. if I need to transform the response of a single route, would that logic live directly inside the controller where I also fetch the data? Or would that logic live inside a middleware that runs after the controller returned the data?

Are there any best practices?
Thanks a lot for your answers :slight_smile:

If it is only used for that controller. just put it in the controller. if you want to use it in multiple controllers put it in a middleware.