0

I need to show an error like the error when user write a wrong data in the login form when user does not enter his password. I think the method I should overwrite is validateLogin()

    protected function validateLogin()
{

    $this->validate(request(), [
        'email' => 'required', 'password' => 'required'
    ]);
}

But it isn't given me the error message in view. I got the error when I left email field empty but not when I left password empty

9
  • That happens by default if are using default Laravel auth module. Are you making a custom login module? Commented May 16, 2018 at 8:35
  • no I'm using the default auth Commented May 16, 2018 at 8:36
  • And what you have tried so far in code? Commented May 16, 2018 at 8:37
  • I tried to overwrite sendFailedLoginResponse() function in my logincontroller but it doesn't help Commented May 16, 2018 at 8:39
  • If you are using the auth module and hasn't changed anything in those files then that error will be thrown by default. Both the required one by the html required attribute or if you have deleted that from Inspector the server side error will be thrown, either way that error will be thrown. Commented May 16, 2018 at 8:40

2 Answers 2

0

The problem wasn't in the ValidateLogin Method it was in the view.

  @if ($errors->has('email'))
       <span class="help-block" style="margin-top:30px;">
           <strong>{{ $errors->first('email') }}</strong>
       </span>
  @endif

I was just need to have the same if condition for the password. thanks for your help

Sign up to request clarification or add additional context in comments.

Comments

0

In your Controller, you can use something like this:

    $validator = Validator::make($request->all(), User::$auth_rules);
    if ($validator->fails()){
        return Redirect::back()->withErrors($validator)->withInput();
    }
    $remember=$request->has('remember')?true:false;
    $user=User::where('email',$request->get('email'))->first();

    if (Auth::attempt(array('email' => $request->input('email'), 'password' => $request->input('password')), $remember)){
        return Redirect::route('dashboard');        
    }

    return Redirect::route('login')->with('status','Invalid credentials');

Hope it helps you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.