tokens() ->where('revoked', false) ->where(function ($q) { $q->whereNull('expires_at')->orWhere('expires_at', '>', now()); }) ->with('client:id,name,revoked') ->latest('created_at') ->get() ->map(fn ($token) => [ 'id' => $token->id, 'client_name' => $token->client?->name, 'client_revoked' => (bool) $token->client?->revoked, 'name' => $token->name, 'scopes' => $token->scopes, 'created_at' => $token->created_at, 'expires_at' => $token->expires_at, ]); } public static function revoke(User $user, string $tokenId): bool { $token = $user->tokens()->where('id', $tokenId)->first(); if (! $token) { return false; } TokenRevocation::revoke($token); return true; } public static function revokeAll(User $user): int { $tokens = $user->tokens()->where('revoked', false)->get(); foreach ($tokens as $token) { TokenRevocation::revoke($token); } return $tokens->count(); } }