How to invalidate all tokens for an user in laravel passport?
Take a look at the HasApiTokens
trait provided by passport. The documentation recommends adding this trait to your User model. One of the methods it provides is tokens()
, which defines a hasMany
relationship between Laravel\Passport\Token
and models using the trait. You can use this to retrieve a list of all of the tokens for a given user:
$userTokens = $userInstance->tokens;
The token model itself has a revoke
method:
foreach($userTokens as $token) { $token->revoke(); }
This worked for ME:
use Laravel\Passport\Token; Token::where('user_id', $user->id) ->update(['revoked' => true]);