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 18bae2b commit da24b94Copy full SHA for da24b94
src/Http/Request.php
@@ -267,6 +267,23 @@ public function getRawBody(): ?string
267
}
268
269
270
+ /**
271
+ * Returns decoded content of HTTP request body.
272
+ */
273
+ public function getBody(): mixed
274
+ {
275
+ $type = $this->getHeader('Content-Type');
276
+ switch ($type) {
277
+ case 'application/json':
278
+ return json_decode($this->getRawBody());
279
+ case 'application/x-www-form-urlencoded':
280
+ return $_POST;
281
+ default:
282
+ throw new \Exception("Unsupported content type: $type");
283
+ }
284
285
+
286
287
/**
288
* Returns basic HTTP authentication credentials.
289
* @return array{string, string}|null
0 commit comments