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

Mick79's avatar

Check if user subscribed - Cashier

Hi I have Laravel Cashier all set up and working. I can go through the stripe process and all my tables update with the correct info etc.

However no matter what

$user = Auth::user();
$user->subscribed()

returns as false. What am I missing?

Thanks

0 likes
10 replies
bashy's avatar

@Mick79 Sorry I meant the name of the subscription in the table. All it does is check the table which match 'default' or one you pass in.

1 like
bwrigley's avatar

@bashy I've got the same question that I can't seem to find an answer too anywhere.

Do you know if there is a way to ask if the user is subscribed to any product?

bwrigley's avatar

sorry scrap that.

The solution is clearly

if ($user->subscriptions){

doh!

(I hope it only return positively if there are active subscriptions)

sheldonscott's avatar

I know this is an older thread, but your answer @bashy regarding the 'default' plan name was a big help. After changing this to match the Stripe name I've established for my overarching subscription plan, this is working as expected.

For anyone else looking:

  • change line 178 in the Cashier Billable file: $subscription should match the name in your Subscriptions table (which is something you named in Stripe)
  • now you should be able to use the if ($user->subscribed('main')) method (or the other methods provided in Cashier)
Shovels's avatar

@BWRIGLEY - Old thread, but for anyone reading this... $user->subscriptions will return any subscription related to the user, regardless of status.

(But thanks @bwrigley you comment helped me find an answer to a slightly different question 😊)

1 like
Top-Master's avatar

Actually, $user->subscriptions is a relation, and will always be null.

But if you eager-load will always be non-null, like:

$user = User::where('id', Auth::id())->with('subscriptions')->firstOrFail();

Where Auth is the Auth-facade.

And if status does matter, chain to above one of Cashier's scope filters.

For example scopeActive(), like:

$user = User::where('id', Auth::id())
    ->with(['subscriptions' => function ($q) {
        $q->active();
    }])
    ->firstOrFail();

Now all we need to do is, see if there are subscriptions:

if ($user->subscriptions->count()) {
}
2 likes
martinbean's avatar

@Top-Master Why have you replied to a thread that was last posted in two years ago?

yarrichar's avatar

@martinbean Why discourage people from participating and providing useful information? I found the answer useful, and another 2 years have passed since then.

1 like

Please or to participate in this conversation.