How to Logout User from API with Laravel Passport
Hello Artisan,
In this tutorial, I will show you how to logout a user from API in Laravel using passport authentication. I will show you the source code of logging out a user from api if you use Laravel passport.
Laravel passport provides a revoke() method and using that method we can easily logout a user from passport based api. So see the below example of how we can logout a user from api.
public function logout()
{
auth()->user()->token()->revoke();
return response()->json([
'message' => 'Successfully logged out'
],200);
}
Read also: Upload Large CSV File using Queue Job Batching in Laravel
Hope it can help you.