You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Livewire数组输入验证错误无法正常渲染问题求助

Livewire数组输入验证错误无法显示的解决方法

问题根源

在@error指令中错误嵌套了Blade变量输出语法{{ $key }},导致Livewire无法正确解析验证错误的属性路径。

修正后的Blade模板代码

直接在@error指令内拼接变量即可,不需要使用双花括号包裹:

<input type="text" class="form-control form-control-solid ps-13" placeholder="{{ __('Visa Name') }}" wire:model.defer="existed_visa_name.{{ $key }}">
@error("existed_visa_name.$key") <span class="error">{{ $message }}</span> @enderror

也可以用字符串拼接的写法:

@error('existed_visa_name.' . $key) <span class="error">{{ $message }}</span> @enderror

额外注意事项

  • 确保组件初始化时,$existed_visa_name数组已包含对应索引的元素(比如在mount方法中初始化$this->existed_visa_name = [''];),否则Livewire无法正确追踪数组元素的验证状态。
  • 保持wire:model.defer的使用逻辑不变,它会延迟输入值的同步,配合save方法中的$this->validate()可以正常触发验证。

内容的提问来源于stack exchange,提问作者Zain Farooq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 21:50:39