55use AlwaysOpen \RequestLogger \Observers \RequestLogObserver ;
66use GuzzleHttp \Psr7 \Request ;
77use Illuminate \Database \Eloquent \Model ;
8+ use Psr \Http \Message \ResponseInterface ;
89
910/**
1011 * AlwaysOpen\RequestLogger\Models\RequestLogBaseModel
1415 * @property string $http_method
1516 * @property int|null $response_code
1617 * @property array|string|null $body
18+ * @property array|string|null $request_headers
1719 * @property array|string|null $response
20+ * @property array|string|null $response_headers
1821 * @property string|null $exception
1922 * @property \Carbon\Carbon|null $occurred_at
2023 */
@@ -25,7 +28,9 @@ class RequestLogBaseModel extends Model
2528 'created_at ' => 'datetime ' ,
2629 'updated_at ' => 'datetime ' ,
2730 'body ' => 'json ' ,
31+ 'request_headers ' => 'json ' ,
2832 'response ' => 'json ' ,
33+ 'response_headers ' => 'json ' ,
2934 ];
3035
3136 protected $ guarded = [
@@ -56,7 +61,19 @@ public static function makeFromGuzzle(Request $request) : static
5661 $ instance ->path = $ request ->getUri ()->getPath ();
5762 $ instance ->http_method = $ request ->getMethod ();
5863 $ instance ->body = $ request ->getBody ()->getContents ();
64+ $ instance ->request_headers = $ request ->getHeaders ();
5965
6066 return $ instance ;
6167 }
68+
69+ public function updateFromResponse (ResponseInterface $ response ): self
70+ {
71+ $ this ->response = json_decode ($ response ->getBody ()->getContents (), true );
72+ $ this ->response_code = $ response ->getStatusCode ();
73+ $ this ->response_headers = $ response ->getHeaders ();
74+
75+ $ this ->save ();
76+
77+ return $ this ;
78+ }
6279}
0 commit comments