我正在尝试Livewire的即时身份验证,它似乎适用于除数组字段之外的其他输入。想知道如何显示数组输入的错误消息。刀片代码
<input type="tel" pattern="[0-9]+" minlength="6" wire:model="contact_phone.{{$index}}"
class="form-control {{ $errors->has('contact_phone.*') ? ' is-invalid' : '' }} " required>
<div>@error('contact_phone') <span class="error text-danger small">{{ $message }}</span> @enderror</div>
验证
public function updated($field)
{
$this->validateOnly($field, [
'contact_phone' => 'required|array|min:1',
'contact_phone.*' => 'required|string|min:3',
]);
}
遵循此文档
这就是我最终让它工作的方式。关键是访问@error指令中输入的特定数组的索引。
<input type="tel" pattern="[0-9]+" minlength="6" wire:model.lazy="contact_phone.{{$index}}"
class="form-control {{ $errors->has('contact_phone.'.$index) ? ' is-invalid' : '' }} " required>
<div>@error('contact_phone.{{$index}}')
<span class="error text-danger small">{{ $message }}</span> @enderror
</div>