user12380208
user12380208

Reputation: 531

In laravel alert not working in view page

I was using alert in a custom registration form for unique email and phone-no but it not working

not working code

@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

when I was used below code it worked but it showing all errors below input area,

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

Upvotes: 0

Views: 105

Answers (1)

sss S
sss S

Reputation: 384

Try the bellow example for individual errors display

 @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

Upvotes: 1

Related Questions