laravel-soulbscription
laravel-soulbscription copied to clipboard
How can I get user subscription count
I would like to get user active subscription counts and also user expired subscription count and user paused subscription count
Hey, thanks for bringing this question! Do you want to check how many times a given user renewed his subscription to a plan?
Hey, thanks for bringing this question! Do you want to check how many times a given user renewed his subscription to a plan?
Yes and also get current active plan count and expired plan count
hi, @lucasdotvin how we can know if the subscription is canceled or deleted
Hello, @hugo-abdou! I'm sorry for taking so long to answer. Are you trying to check if the last subscription is canceled? If so, you can try checking the lastSubscription()
method:
https://github.com/lucasdotvin/laravel-soulbscription#expired-subscriptions
Hello, @hugo-abdou! I'm sorry for taking so long to answer. Are you trying to check if the last subscription is canceled? If so, you can try checking the
lastSubscription()
method: https://github.com/lucasdotvin/laravel-soulbscription#expired-subscriptions
Yes and also get current active plan count and expired plan count
@lucasdotvin @Temian1 have you find solution how to get current subscription?
No
@Temian1 I believe at any given time, a subscriber can only have one main subscription(plan) at any point in time. I dont think this package has add-on plan subscription yet.
I read something about tickets
. Perhaps, it has something to do with your question.
Hello! Is there a way to see all subscribers and their status? as a collection that lists all subscribers and their status (active, pending, cancelled, etc) @frknasir
@pixsolution there isn't. But, you can easily build a query for that.
can you give more detail please? how could I do? Because in the subscriptions table I only see dates, the only logic I can think of is to build an status column ( active, pending, etc) based on the current date vs. the expiration date. If you have another idea, I'll like to hear it.
Another question, the expiration is automatic right? Based on the expiration date, the package already takes care of that, right?
Thanks @frknasir
i'd do something like the following.
$models = Model::with('subscription.plan')->get();
This will get all the subscribers with their subscription details and the plan of the subscription.
I would also add methods(that return cast attributes) on the subscriber Model
to easily retrieve the active
, cancelled
, pending
, suppressed
etc....and this just mostly writing logic based on the date fields. For example, a method to understand if a subscriber model's subscription is active would be:
/**
* Check if subscriber has active subscription.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute
*/
protected function hasActiveSubscription(): Attribute
{
return Attribute::make(
get: fn () => is_null($this->subscription?->canceled_at) && is_null($this->subscription?->expired_at) &&
$this->subscription?->started_at->isPast() && .... ,
);
}
And then something like $model->has_active_subscription
will either be true
or false
.
I hope that was helpful. :)
You can look at this file for more helpful methods: https://github.com/lucasdotvin/laravel-soulbscription/blob/develop/src/Models/Concerns/HasSubscriptions.php#L138
ok thanks @frknasir I will try that since it is important to give the status of the subscription to the user