5
votes

I am making an API using Lumen and Fractal, but I got an error

Method attempt does not exist

while trying to login. Can somebody help me to solve this? This is my controller:

public function login(Request $request, User $user)
{
    if (!Auth::attempt(['email' => $request->email, 'password'  => $request->password])) {
        return response()->json(['error' => 'email or password wrong'], 401);
    }

    $user = $user->find(Auth::user()->id);

    return fractal()
        ->item($user)
        ->transformWith(new UserTransformer)
        ->addMeta([
            'token' => $user->api_token,
        ])
        ->toArray();
}

this is my error

(1/1) BadMethodCallException Method attempt does not exist. in Macroable.php (line 74)

1
Hi Easy learn did you got any solution to get that fixed, I am facing same issue using using Lumen 5.5Puneet
Method attempt doesn't exist, You can use check method instead of attempt.Gautam
can you show me your user model? You need to actually implement those methods defined by the contract. Use the Authenticatable trait.Gaurang Ghinaiya

1 Answers

0
votes

in your bootstrap/app.php file did you uncomment either of these lines around line 26 or around lines 81-83?

// $app->withFacades();

// $app->withEloquent();