Try this:
auth()->guard('api')->setUser($user);
attempt() is only available to guards implementing the StatefulGuard interface.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hi guys , in my project i have a part that i want to manually logs in a user in my api guard , now what i have tried is that :
auth()->guard('api')->attempt($mobile,$password);
but i get this error :
"Method Illuminate\Auth\RequestGuard::attempt does not exist.", "exception": "BadMethodCallException", "
i tried to use :
$user = Auth::login($user);
but this logs the user in into web guard and not the api guard . another way i used the :
dd($user->createToken($user->name));
i have the token now and i wanted to know if its possible to logs the user into guard('api') and have it authenticated . thanks in advance
Try this:
auth()->guard('api')->setUser($user);
attempt() is only available to guards implementing the StatefulGuard interface.
Please or to participate in this conversation.