How to check if there is an error in the Laravel Blade with the @error tag Laravel 5.8.13?

Asked

Viewed 247 times

1

Well in Laravel 5.8.13 there was an update in which instead of using:

@if ($errors->has('email'))
    <span>{{ $errors->first('email') }}</span>
@endif

can be used:

@error('email')
    <span>{{ $message }}</span>
@enderror

but I wanted to know how to check if you have any error not a specific one with the same function of:

@if($errors->all())
    <span>{{ $errors->first('email') }}</span>
@endif
  • 1

    There is the $errors->any() that does this.

1 answer

3


Hello, From what I understand of your doubt. Have you tried using the code below:

@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif
  • Thanks tbm guy works, but I wanted to know if there is a version as tag, using the @error tag, but already helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.