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

Systemlord's avatar

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.

0 likes
0 replies

Please or to participate in this conversation.