Skip to content

Commit a7db414

Browse files
committed
feat: return parsed data when validation succeeds
1 parent 0373670 commit a7db414

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Request.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,30 @@ public static function headers($key = null, bool $safeData = true)
308308

309309
/**
310310
* Validate the request data
311+
*
311312
* @param array $rules The rules to validate against
312-
* @return bool
313+
*
314+
* @return false|array Returns false if validation fails, or the validated data if validation passes
313315
*/
314316
public static function validate(array $rules)
315317
{
316-
return \Leaf\Form::validate(static::body(false), $rules);
318+
$data = \Leaf\Form::validate(static::body(false), $rules);
319+
320+
if ($data === false) {
321+
return false;
322+
}
323+
324+
return static::body();
317325
}
318326

319327
/**
328+
* Return the auth instance
320329
* @return \Leaf\Auth
321330
*/
322331
protected static function auth()
323332
{
324333
if (!class_exists('\Leaf\Auth')) {
325-
throw new \Exception("You need to install the leaf-auth package to use the auth helper");
334+
throw new \Exception("You need to install the leafs/auth package to use the auth helper");
326335
}
327336

328337
if (!(\Leaf\Config::get('auth.instance'))) {

0 commit comments

Comments
 (0)