diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 3e76696..69b5528 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -148,9 +148,11 @@ public function pendingReferralRewards(Request $request) { $target = User::REFERRAL_SUBSCRIPTION_TARGET; + // Use has() (a correlated subquery in WHERE) rather than having() on the + // withCount alias — Postgres does not allow select aliases in HAVING. $users = User::withCount('referrals') ->whereNull('referral_subscription_granted_at') - ->having('referrals_count', '>=', $target) + ->has('referrals', '>=', $target) ->orderByDesc('referrals_count') ->get(['id', 'uuid', 'first_name', 'last_name', 'email', 'mobile', 'referral_code']);