Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afshin.asghari's avatar

Auto delete revoked token by expiration date from database

As suggested on the title, I'm using Laravel Passport and trying to figure out how to change some core functions so that when expire date hits a token, it gets removed from the database instead of having its revoked property true! I don't really see the point in having old tokens in the database, but if there is a reason for that I would be thankful if you could enlighten me.

0 likes
3 replies
isa's avatar

Hi. You can listen for Laravel\Passport\Events\AccessTokenCreated event and inside your listener, and remove any revoked and/or expired tokens for a user.

Sure thing, you are able to make new artisan command, which will look into tokens table, and remove expired tokens. Using schedule, run that command once a day, or whatever frequency you like.

afshin.asghari's avatar

@BOZHKOS - which method do you think is the best, server performance wise, Event or schedule? btw the Event method worked fine! many thanks.

isa's avatar
isa
Best Answer
Level 12

@AFSHIN.ASGHARI - I think in terms of performance, these two methods are equivalent. Thing is, using an event, you remove all unnecessary user tokens immediately, whenever scheduler will remove all expired tokes for all users, once a day (or whatever frequency you choose).

It is more about what way fits better for your app :)

1 like

Please or to participate in this conversation.