laravel警报在视图页面中不起作用

问题描述 投票:0回答:1

我在自定义注册中使用警报来自唯一的电子邮件和电话,否,但不起作用

非工作代码

@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

当我在下面的代码中使用时,它可以工作,但是会在输入区域下方显示所有错误,

code

 @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
php laravel laravel-5.7
1个回答
0
投票

尝试以下显示单个错误的示例

 @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
© www.soinside.com 2019 - 2024. All rights reserved.