I am using
- Laravel Framework 7.28.4
- guzzlehttp/guzzle: "^7.2",
- PHP 8.0.5
I am consuming some third party API's in laravel using Http Client
What I need: I need to log every request and response in the file to track for further use.
I was follow some of blogs and answers.
1 https://medium.com/@sirajul.anik/logging-request-response-for-guzzle-bbea1f54cd87
[2] https://github.com/bilfeldt/laravel-http-client-logger
[3] Laravel - Log Guzzle requests to file
Above [3] link working as mentioned when calling in web.php with given method. This worked
$client = app('GuzzleClient')([
'base_uri' => 'https://jsonplaceholder.typicode.com/',
'timeout' => 10,
'verify' => false,
]);
$request = $client->get('users', [
'headers' => [ 'accept' => 'application/json']
]);
$response = json_decode((string) $request->getBody());
But I am using this single line API call using HTTP class like this where I am not creating any new object by own.
$response = Http::withBody(
json_encode($reqArray), 'application/json')->withToken($token)->post($SearchByNameApi);
Can someone help to achieve this, how my API Call logs into a file?