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

geetpurwar's avatar

Laravel Time Issue : Restoring Credits Every Month (Exact date)

Hi,

I am assigning 1000 credits to user on the day user signup (Example : 31st Jan 2020)

Now how do I restore those credits again on the renewal every month. Feb will have different date 28th or 29th Feb 2020 March credits will be restored again on 31st March 2020 April credits again on 30th April and so on.

I have created last_credit_date and it works fine for 1st month using Carbon function addMonthsNoOverflow() and updating last_credit_date to same date (29th Feb 2020)

Issue happens when I use addMonthsNoOverflow() again next month as this will change date to 29th march instead of 31st March as expected.

Please advise.

0 likes
4 replies
Sinnbeck's avatar

Why not just save the very first date and always use that as base for calculation?

You can still keep the other column to keep track of your last credit date

2 likes
Snapey's avatar

You could decide that if you join on the 29th, 30th or 31st that your join date is the 28th and then renew credits on the 28th of every month.

In the very first month they get renewed slightly early, but does a few days make any difference?

Or you could renew everyone's credits on the 1st of the month, and in the very first month they only get a portion of the credits to take them to the first of month.

geetpurwar's avatar

@Snapey I have thought of that. But I am also using Laravel Spark with Stripe for paid plans, which uses last date pattern.

Example: If a user subscribes on 31st Jan, he will be renewed on 28th Feb, and again on 31st March. So I have to follow the same pattern for free plans.

Let me know your thoughts.

Please or to participate in this conversation.