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 b2a5951 commit a20fb8fCopy full SHA for a20fb8f
src/Http/Request.php
@@ -267,6 +267,20 @@ 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
+ return match ($type) {
277
+ 'application/json' => json_decode($this->getRawBody()),
278
+ 'application/x-www-form-urlencoded' => $_POST,
279
+ default => throw new \Exception("Unsupported content type: $type"),
280
+ };
281
+ }
282
+
283
284
/**
285
* Returns basic HTTP authentication credentials.
286
* @return array{string, string}|null
0 commit comments