Skip to content

Commit

Permalink
feat: add option to return full data
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Aug 19, 2023
1 parent a7db414 commit 36be8ac
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,19 @@ public static function headers($key = null, bool $safeData = true)
* Validate the request data
*
* @param array $rules The rules to validate against
* @param boolean $returnFullData Return the full data or just the validated data?
*
* @return false|array Returns false if validation fails, or the validated data if validation passes
*/
public static function validate(array $rules)
public static function validate(array $rules, bool $returnFullData = false)
{
$data = \Leaf\Form::validate(static::body(false), $rules);

if ($data === false) {
return false;
}

return static::body();
return $returnFullData ? $data : static::get(array_keys($rules));
}

/**
Expand All @@ -331,7 +332,7 @@ public static function validate(array $rules)
protected static function auth()
{
if (!class_exists('\Leaf\Auth')) {
throw new \Exception("You need to install the leafs/auth package to use the auth helper");
throw new \Exception('You need to install the leafs/auth package to use the auth helper');
}

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

0 comments on commit 36be8ac

Please sign in to comment.