From 80eb42baf755197ef59b593531ece30c73c046fd Mon Sep 17 00:00:00 2001 From: Erik Wittek Date: Thu, 14 Oct 2021 11:37:49 +0200 Subject: [PATCH] Make it possible to validate nested array input --- src/WizardStep.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/WizardStep.php b/src/WizardStep.php index 5a98f0f..52c15a4 100644 --- a/src/WizardStep.php +++ b/src/WizardStep.php @@ -3,6 +3,7 @@ namespace Arcanist; use function collect; +use Illuminate\Support\Arr; use Illuminate\Http\Request; use Illuminate\Support\Collection; use Illuminate\Validation\ValidationException; @@ -138,7 +139,11 @@ protected function data(?string $key = null, mixed $default = null): mixed protected function rules(): array { return collect($this->fields()) - ->mapWithKeys(fn (Field $field) => [$field->name => $field->rules]) + ->mapWithKeys(function (Field $field) { + return Arr::isAssoc($field->rules) + ? $field->rules + : [$field->name => $field->rules]; + }) ->all(); } }