Skip to content

Commit

Permalink
Replace foreach loop with collection mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jan 18, 2023
1 parent ed5a615 commit ab3bd31
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Hyde\Framework\Concerns\InvokableAction;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Support\Collection;
use function collect;
use function json_decode;
use stdClass;
use function validator;
Expand Down Expand Up @@ -88,11 +89,9 @@ protected function makeFieldsValidator(): void

if (is_array($this->schema->fields)) {
foreach ($this->schema->fields as $field) {
foreach ($rules as $key => $rule) {
$input[$key] = $field->{$key} ?? null;
}

$this->fieldValidators->add(validator($input, $rules));
$this->fieldValidators->add(validator(collect($rules)->mapWithKeys(function ($rule, $key) use ($field): array {
return [$key => $field->{$key} ?? null];
})->all(), $rules));
}
}
}
Expand Down

0 comments on commit ab3bd31

Please sign in to comment.