To filter out users who have both subscription types, you can modify the query to check if the user has both subscription types and exclude them from the results. Here's an example:
public function filteredOrAll(?string $type): ChildBuilder|Builder|static
{
if ($type) {
return $this->where(function ($query) use ($type) {
$query->whereDoesntHave('subscriptions.subscriptionItems.sku.product', function ($query) use ($type) {
$query->where('type', $type);
})->orWhereDoesntHave('subscriptions.subscriptionItems.sku.product', function ($query) use ($type) {
$query->where('type', '!=', $type);
});
});
}
return $this;
}
This query uses whereDoesntHave to check if the user doesn't have a subscription of the specified type, and orWhereDoesntHave to check if the user doesn't have a subscription of the other type. This way, if the user has both subscription types, they will be excluded from the results.
Note that this assumes that there are only two subscription types. If there are more, you'll need to modify the query accordingly.