DEV Community

AquaCat
AquaCat

Posted on

3

【Laravel Sanctum】How to fix an error "BadMethodCallException: Method Illuminate\Auth\RequestGuard::logout does not exist. "

Version...
Laravel Framework 8.83.26
Laravel Sanctum 2.11

An error message below showed up when logging out.

BadMethodCallException: Method Illuminate\Auth\RequestGuard::logout does not exist.

It says "logout does not exist." Looks like the code "Auth::logout();" has a problem.

Solution

Change "Auth::logout();" to

Auth::guard('web')->logout();
Enter fullscreen mode Exit fullscreen mode

If you are using API tokens, try code below. (I have not tried this yet!)

Auth::guard('sanctum')->user()->tokens()->delete();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay