Response Data Controler

You did it the right way, kind of.

Check the documentation for controllers.

You can also create a middleware for your route, in this you can intercept the request and amend any data you need to before it is returned.

Hope that helps!