0
votes

I'm new at Laravel and I want to Use the authentification system included in Laravel. To do so I activated authentification in my laravel projet with

php artisant make:auth

Then I tryed to log in in the my projet and everthing works but the error messages like "e-mail field is required" aren't shown when I submit the empty form.

Here is an example of the error test auto implemented in my login.blade.php :

<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
          <div class="col-md-12">
              <input id="email" type="email" class="form-control" placeholder="{{ trans('validation.attributes.email') }}" name="email" value="{{ old('email') }}" required autofocus>

              @if ($errors->has('email'))
                  <span class="help-block">
                      <strong>{{ $errors->first('email') }}</strong>
                  </span>
              @endif
          </div>
</div>

Please notice that when I enter a bad combinaison of email/password the error message is shown correctly but for any other case the page doesn't even refresh.

Thank you for your help ...

1

1 Answers

0
votes

You input email field is required. Your browser probably does not submit the request because of this. If you remove the "require" attribute from your email input, the error should be shown.

<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
      <div class="col-md-12">
          <input id="email" type="email" class="form-control" placeholder="{{ trans('validation.attributes.email') }}" name="email" value="{{ old('email') }}" autofocus>

          @if ($errors->has('email'))
              <span class="help-block">
                  <strong>{{ $errors->first('email') }}</strong>
              </span>
          @endif
      </div>

Also, you can use this code to show "all" errors when they occur:

@if (count($errors) > 0)
    <div class="alert alert-danger">
        <strong>Whoops!</strong><br><br>
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif