ndev ndev - 2 months ago 18
PHP Question

Laravel Auth Custom Fields

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'
]);

Answer

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('/');
       }
}
Comments