I was answering some Laravel questions on StackOverflow this week when I stumbled on a question asking how to enable GZIP compression on responses when using Laravel Vapor. We host a number of applications on Laravel Vapor and this was something we'd solved, but a cursory search of Google didn't return anything that explained how to do this (at least at the time this was written).
Assuming we want to encode the response and are able to, we set the content of the response to be the compressed version.
Like any middleware, you can choose to apply this at a per route level, add it to a particular group of middleware, or add it as global middleware. In our apps, we've added it as global middleware and then we just ask for a GZIP'd response when we need to do so.