noblemfd
1 month ago
144
3
Laravel

How to Validate and show a message for wrong username and password

Posted 1 month ago by noblemfd

I have this controller and view

class LoginController extends Controller
{
   protected $redirectTo = '/dashboard';

   public function __construct()
  {
     $this->middleware('guest')->except('logout');
  }
}

View

       <form action="{{ route('login') }}" method="POST">
            {{ csrf_field() }}
            
            <div class="input-group mb-3">
                <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" placeholder="Username or Email" value="{{ old('email') }}" required autofocus>
                <div class="input-group-append">
                    <!--<span class="fa fa-envelope input-group-text"></span>--> 
                <div class="input-group-text">
                    <span class="fas fa-user"></span>
                </div>
                    @if ($errors->has('email'))
                    <span class="invalid-feedback" role="alert">
                       <strong>{{ $errors->first('email') }}</strong>
                    </span> 
                    @endif
                </div>
            </div>

            <div class="input-group mb-3">
                <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" placeholder="Password" name="password" required>
                <div class="input-group-append">
                <div class="input-group-append">
                  <div class="input-group-text">
                    <span class="fas fa-lock"></span>
                  </div>
                </div>
                    @if ($errors->has('password'))
                    <span class="invalid-feedback" role="alert">
                        <strong>{{ $errors->first('password') }}</strong>
                    </span> @endif
                </div>
            </div>

            <div class="row">
                <div class="col-8">
                    <input type="checkbox" name="remember"> {{ trans('global.remember_me') }}
                </div>
                <!-- /.col -->
                <div class="col-4">
                    <button type="submit" class="btn btn-primary btn-block btn-flat">{{ trans('global.login') }}</button>
                </div>
                <!-- /.col -->
            </div>
        </form>

At Login, I want the application to show a message whenever the user entered wrong username or password. What's it's only doing now is when its not an email.

How do I achieve this?

Thank you

Please sign in or create an account to participate in this conversation.