['required', 'array', 'min:1', 'max:500'], 'events.*.user' => ['required', 'string', 'max:255'], 'events.*.source_ref' => ['required', 'string', 'max:255'], 'events.*.topic' => ['sometimes', 'nullable', 'string', 'max:255'], ] + EventRules::itemPrefixed('events.*.'); } public function messages(): array { return EventRules::messages('events.*.'); } public function after(): array { return [function (Validator $v) { foreach ((array) $this->input('events', []) as $i => $item) { if (! is_array($item)) { continue; } foreach (EventRules::check($item) as $field => $error) { if ($v->errors()->missing("events.$i.$field")) { $v->errors()->add("events.$i.$field", $error); } } } }]; } /** @return list> */ public function items(): array { return array_map(function (array $item) { $item['topic'] = (string) ($item['topic'] ?? ''); return $item; }, $this->validated()['events']); } }