Maybe this is a working solution. I tried following the logic @TaylorOtwell uses in the Cashier package to check if the subscription is active. I have added this as the query scope on the Listing model.
public function scopeSubscribed($query)
{
return $query->whereHas('user', function ($r) {
$r->whereHas('subscriptions', function ($s) {
$s->whereNested(function ($t) {
$t->where('name', 'main') // name of subscription
->whereNull('ends_at')
->orWhere('ends_at', '>', Carbon::now())
->orWhereNotNull('trial_ends_at')
->where('trial_ends_at', '>', Carbon::today());
});
});
});
}
It appears to work. Sucks It has to be done like this.