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

geerizzle's avatar

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?

0 likes
2 replies
Cronix's avatar
Cronix
Best Answer
Level 67

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();
    }
1 like
geerizzle's avatar

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 or to participate in this conversation.