We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 11b260d commit a3719caCopy full SHA for a3719ca
src/Http/Request.php
@@ -266,6 +266,20 @@ public function getRawBody(): ?string
266
}
267
268
269
+ /**
270
+ * Returns decoded content of HTTP request body.
271
+ */
272
+ public function getDecodedBody(): mixed
273
+ {
274
+ $type = $this->getHeader('Content-Type');
275
+ return match ($type) {
276
+ 'application/json' => json_decode($this->getRawBody()),
277
+ 'application/x-www-form-urlencoded' => $_POST,
278
+ default => throw new \Exception("Unsupported content type: $type"),
279
+ };
280
+ }
281
+
282
283
/**
284
* Returns basic HTTP authentication credentials.
285
* @return array{string, string}|null
0 commit comments