There is a HTTP GET request made from angular frontend and that request is hitting our PHP controller. We are generating a reference number in controller and making some external API calls to prepare some data. I need the controller to return a response to the get request first with generated reference number and then continue doing other external API calls to prepare data.
My question is how can I achieve returning the response first from controller and then continue with other logic in same controller.
I have taken reference from here
but still controller function doesn’t actually return response until the finally block completes.
try {
return response("", 200);
} finally {
// Controller logic here
}
2
Answers
You should probably use a Queue for that. See the Docs.
Simple example:
There is also a terminable middleware. Search it in the documentation Laravel difference between terminable middleware and after middleware