Mar 24, 2021
0
Level 1
Filter all users by description
Hey there, I am getting my feet wet with laravel spark/cashier. Currently I want to show my admin a list of users that can be filtered by hasSubscription - so it should return all users that have an active or ongoing subscription or users that don't have an active subscription.
I was searching through the docs but didn't find such an example. Can you help me?
Currently that is my solution:
if($has_subscription == 'true'){
return $query->whereHas('subscriptions', function ($s) {
$s->where(function ($t) {
$t->whereNull('ends_at')
->orWhere('ends_at', '>', Carbon::now())
->orWhereNotNull('trial_ends_at')
->where('trial_ends_at', '>', Carbon::today());
});
});
} else{
return $query->whereDoesntHave('subscriptions',function ($s) {
$s->where(function ($t) {
$t->whereNull('ends_at')
->orWhere('ends_at', '>', Carbon::now())
->orWhereNotNull('trial_ends_at')
->where('trial_ends_at', '>', Carbon::today());
});
});
}
Will that work? I sadly have no user yet that had a subscription that ran out.
Please or to participate in this conversation.