5
5
use AlwaysOpen \RequestLogger \Observers \RequestLogObserver ;
6
6
use GuzzleHttp \Psr7 \Request ;
7
7
use Illuminate \Database \Eloquent \Model ;
8
+ use Psr \Http \Message \ResponseInterface ;
8
9
9
10
/**
10
11
* AlwaysOpen\RequestLogger\Models\RequestLogBaseModel
14
15
* @property string $http_method
15
16
* @property int|null $response_code
16
17
* @property array|string|null $body
18
+ * @property array|string|null $request_headers
17
19
* @property array|string|null $response
20
+ * @property array|string|null $response_headers
18
21
* @property string|null $exception
19
22
* @property \Carbon\Carbon|null $occurred_at
20
23
*/
@@ -25,7 +28,9 @@ class RequestLogBaseModel extends Model
25
28
'created_at ' => 'datetime ' ,
26
29
'updated_at ' => 'datetime ' ,
27
30
'body ' => 'json ' ,
31
+ 'request_headers ' => 'json ' ,
28
32
'response ' => 'json ' ,
33
+ 'response_headers ' => 'json ' ,
29
34
];
30
35
31
36
protected $ guarded = [
@@ -56,7 +61,18 @@ public static function makeFromGuzzle(Request $request) : static
56
61
$ instance ->path = $ request ->getUri ()->getPath ();
57
62
$ instance ->http_method = $ request ->getMethod ();
58
63
$ instance ->body = $ request ->getBody ()->getContents ();
64
+ $ instance ->request_headers = $ request ->getHeaders ();
59
65
60
66
return $ instance ;
61
67
}
68
+
69
+ public function updateFromResponse (ResponseInterface $ response ): self {
70
+ $ this ->response = json_decode ($ response ->getBody ()->getContents (), true );
71
+ $ this ->response_code = $ response ->getStatusCode ();
72
+ $ this ->response_headers = $ response ->getHeaders ();
73
+
74
+ $ this ->save ();
75
+
76
+ return $ this ;
77
+ }
62
78
}
0 commit comments