Skip to content

Commit 4e761f0

Browse files
committed
feat: add rawData method
1 parent 57d5724 commit 4e761f0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Request.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ public static function try(array $params, bool $safeData = true, bool $noEmptySt
163163
return $data;
164164
}
165165

166+
/**
167+
* Get raw request data
168+
*
169+
* @param string|array $item The items to output
170+
* @param mixed $default The default value to return if no data is available
171+
*/
172+
public static function rawData($item = null, $default = null)
173+
{
174+
$handler = fopen('php://input', 'r');
175+
$decoded = json_decode(stream_get_contents($handler), true);
176+
$data = is_array($decoded) ? $decoded : [];
177+
178+
return \Leaf\Anchor::deepGet($data, $item) ?? $default;
179+
}
180+
166181
/**
167182
* Returns request data
168183
*

0 commit comments

Comments
 (0)