2

Trying to add a custom field to auth, to check if a user is 'activated' before allowing login

I've tried modifying AuthenticatesUsers.php although I now understand this file shouldnt be edited directly.

Here is what I tried and it did not work.

    public function postLogin(Request $request)
{
    $this->validate($request, [
        $this->loginUsername() => 'required', 'password' => 'required', 'activated' => '1'
    ]);

1 Answer 1

4

You can also add the custom field by manaually authenticating the users.

public function postLogin(Request $request)
{
    $this->validate($request, [
        $this->loginUsername() => 'required', 'password' => 'required'
    ]);
      if (Auth::attempt(['email' => $request->email, 'password' => $request->password,'activated'=>1]) )
       {     
            return redirect()->intended('/');
       }
}
Sign up to request clarification or add additional context in comments.

1 Comment

where do I add this?

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.