Skip to content

Commit

Permalink
Only return validated data
Browse files Browse the repository at this point in the history
  • Loading branch information
SiebeVE committed Sep 21, 2020
1 parent ffaa43e commit 6929f58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ComponentConcerns/ValidatesInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public function validate($rules = null, $messages = [], $attributes = [])

$this->shortenModelAttributes($data, $rules, $validator);

$validator->validate();
$validatedData = $validator->validate();

$this->resetErrorBag();

return $data;
return $validatedData;
}

public function validateOnly($field, $rules = null, $messages = [], $attributes = [])
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ public function validation_passes_when_same_rule_is_used_and_matches()
->call('runSameValidation')
->assertDontSee('The password and password confirmation must match');
}

/** @test */
public function only_data_in_validation_rules_is_returned()
{
$component = new ForValidation();
$component->bar = 'is required';

$validatedData = $component->runValidationWithoutAllPublicPropertiesAndReturnValidatedData();
$this->assertSame([
'bar' => $component->bar,
], $validatedData);
}
}

class ForValidation extends Component
Expand Down Expand Up @@ -435,6 +447,11 @@ public function runSameValidation()
]);
}

public function runValidationWithoutAllPublicPropertiesAndReturnValidatedData()
{
return $this->validate(['bar' => 'required']);
}

public function render()
{
return app('view')->make('dump-errors');
Expand Down

0 comments on commit 6929f58

Please # to comment.