laravelvalidationauthentication

Laravel attempt() method is undefined (JWT)


I am trying to authenticate users in Laravel using JWT. In my auth controller I have this login method:

public function login(Request $request)
    {
        $jwt_token = null;

        $input = $request->only("email", "password");

        if (!$jwt_token = auth('users')->attempt($input)) {
            return response()->json([
                'success' => false,
                'message' => 'invalid email or password'
            ]);
        }

        return response()->json([
            'success' => true,
            'token' => $jwt_token,
        ]);
    }

But the attempt method is "undefined". The same happens if I use

auth('users')->JWTAuth::attempt($input)

Any help on this is appreciated.


Solution

  • It should not be called as auth('users')->JWTAuth::attempt($input);

    Try with: auth('users')->attempt($input);