Is your plan called 'default'?
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
Hi @bashy
Sorry, no it isn't. I don't follow?
@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.
@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?
sorry scrap that.
The solution is clearly
if ($user->subscriptions){
doh!
(I hope it only return positively if there are active subscriptions)
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)
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
Authis 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()) {
}
@Top-Master Why have you replied to a thread that was last posted in two years ago?
@martinbean Why discourage people from participating and providing useful information? I found the answer useful, and another 2 years have passed since then.
Please or to participate in this conversation.