['required', 'integer', 'exists:history_types,id'], 'body' => ['required', 'string', 'max:65535'], // The picker emits a naive local datetime; presence is enforced // conditionally below based on the chosen type. 'occurred_at' => ['nullable', 'date_format:Y-m-d\TH:i:s'], ]; } public function withValidator(Validator $validator): void { $validator->after(function (Validator $validator) { $typeId = $this->input('history_entry_type_id'); if (! $typeId) { return; } $type = HistoryType::find($typeId); if ($type && $type->requires_datetime && ! $this->filled('occurred_at')) { $validator->errors()->add( 'occurred_at', 'Für diesen Verlaufstyp sind Datum und Uhrzeit erforderlich.' ); } }); } }