I would create a middleware and group the routes which will count into the total of requests with it, and each time a request is made you can increase the count for the specific user and also prevent the call in case the limit has been reached so you can redirect them to a payment / upgrade of plan page.
Dec 5, 2021
2
Level 2
Counting Sanctum API usage
I have a SaaS which is served using APIs created with Laravel Sanctum. I want to keep track of API usage count as there will be monthly subscription plans based on each having limit on the API usage. For eg: Plan 1 -> costs $10 -> 1000 requests per day Plan 2 -> costs $20 -> 2500 requests per day and so on.
What is the best approach to do this?
Please or to participate in this conversation.