我在自定义注册表单中使用警报来发送唯一的电子邮件和电话,否,但不起作用
无效代码
@if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
@if ($errors->has('phone'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('phone') }}</strong>
</span>
@endif
当我在下面的代码中使用它时,它可以工作,但会在输入区域下方显示所有错误,
代码
@if($errors->has('email'))
@foreach($errors->all() as $error)
<li style="color:red">{{ $error }}</li>
@endforeach
@endif
@if($errors->has('phone'))
@foreach($errors->all() as $error)
<li style="color:red">{{ $error }}</li>
@endforeach
@endif
答案 0 :(得分:1)
尝试下面的示例显示单个错误
@if ($errors->any())
<label for="email" class="error">{{ $errors->first('email') }}</label>
@endif
@if ($errors->any())
<label for="phone" class="error">{{ $errors->first('phone') }}</label>
@endif