Create a middleware and use terminate method to log your response.
https://laravel.com/docs/9.x/middleware#terminable-middleware
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I want to keep track of API requests as a log with status codes (200, 422, 500). I am able to handle the 422 and 500 status code APIs with App\Exceptions\Handler.php class where on error I can log the API request with the appropriate status code.
Is there any way to do it for API requests with 200 status? In other words which Laravel class/service runs on before the response is sent to the client.
Create a middleware and use terminate method to log your response.
https://laravel.com/docs/9.x/middleware#terminable-middleware
Please or to participate in this conversation.