vendredi 25 octobre 2019

What is the opposite of middleware in Laravel?

Middleware in Laravel can be used to add app wide logic (or specific to specific routes or group of routes) before any application/business logic is applied. I want to do the same, but after all the application/business logic is done. What I love about middleware is that it centralizes the place where said logic is applied. Is there a way to do that at the end of the request/response lifecycle?

One option is using transformers, but I don't find it as clean as middleware for some reason (maybe b/c it's done by a third party?)

sample use case: I want to have a group of endpoints always return values in an alternate currency rather than USD only when such requests are made from a certain type of shoppers from a certain geographical area (which I already know). So I will need to perform business logic, and then right before I send the json response back, I want to "hijack" said response and replace all USD values with another currency of my choosing.

Ideas? (I'm using Laravel 5.5)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire