How to use echo in a Laravel view?

3

I want my layout blade echo only if the $errors variable is set:

@section('mensagens')
    <div class="container"> 
      <div class="row"> 
        <div class="col-md-2"></div>
        {{ isset($errors) ? 
            '<div class="col-md-8 alert alert-danger">'
              $errors->first('prontuario')
              $errors->first('senha')
            '</div>'
            :
            ''
        }}

        <div class="col-md-2"></div>
      </div>
    </div>

    @show

How do I just show this div of class alert-danger if the $errors variable of my form is set?

    
asked by anonymous 01.11.2016 / 14:17

2 answers

3

You can also do this:

@section('mensagens')
<div class="container"> 
  <div class="row"> 
    <div class="col-md-2"></div>
        @if (count($errors))
            <div class="col-md-8 alert alert-danger">
                @foreach ($errors->all() as $error)
                    {{ $error }}
                @endforeach
            </div>
        @endif
    <div class="col-md-2"></div>
  </div>
</div>
@show

Instead of setting each individual error, you go through all the errors and display each one.

    
01.11.2016 / 14:29
0

Use @if and @endif

@section('mensagens')
    <div class="container"> 
      <div class="row"> 
      @if($errors)
          <div class="col-md-2"></div>
              <div class="col-md-8 alert alert-danger">
                  {{ $errors->first('prontuario') }}
                  {{ $errors->first('senha') }}
              </div>
              <div class="col-md-2"></div>
          </div>
      @endif
    </div>
@show
    
01.11.2016 / 14:19