UserSubscribed event listener - no Auth::user() ? I want to do some stuff when a user subscribes so I added an event listener to 'Laravel\Spark\Events\Subscription\UserSubscribed'
It triggers OK, but when I try to get the user with Auth::user() this fails.
I wonder if this is because the subscribe event is done before the user is created and/or logged in? How can I manage this?
You should be able to just access $event->user in the listeners handle() method. The user is already passed to the event.
Look at their UpdateActiveSubscription listener (which is listening to that same event) to see how they're doing it. eg
public function handle($event)
{
$currentPlan = $event instanceof SubscriptionCancelled
? null : $event->user->subscription()->provider_plan;
$event->user->forceFill([
'current_billing_plan' => $currentPlan,
])->save();
}
Fantastic thanks, easy!
Related to subscriptionsdo you know why there is a stripe_plan created both in users and subscriptions table, which one is active or can be used as an identifier for other things?
Please sign in or create an account to participate in this conversation.