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

danielmeade's avatar

Fire event at the end of users subscription

I'm using Spatie Newsletter - https://github.com/spatie/laravel-newsletter to subscribe newly registered users to a MailChimp mailing list.

I need to unsubscribe users from the list if they cancel their subscription, but I only want to do this once their current billing cycle has ended.

I'm unsure of where I need to handle this logic and how to prevent the unsubscribe from firing immediately.

Any pointers?

(I'm really new to Laravel so please forgive me if this reeks of a stupid question).

0 likes
1 reply
Cronix's avatar

I haven't tried this, but a few thoughts: When a user cancels their subscription, the ends_at column gets populated in the subscriptions/team_subscriptions table with the datetime that you're wanting (it shows when they would have renewed on the next month - in other words, at the end of their current subscription). You could use that and just have a daily() laravel scheduled task that scans those 2 tables for a date that was today and remove the newsletter subscription for those users. I think that would be the simplest.

You could also hook into the SubscriptionCancelled event that Spark triggers, grab the ends_at date, put it in another table and use that to do the purges with a daily() scheduled task, but has more work involved. You'd also have to take into account if they resumed the subscription after cancelling. Using my first scenario, it would account for that automatically because ends_at would become null again and the newsletter wouldn't get unsubscribed on that day, whereas you'd have to do that manually using the 2nd method. https://spark.laravel.com/docs/8.0/billing#billing-events

Please or to participate in this conversation.