join('mne.parties as p', 'p.id', '=', 'l.party_id') ->join('public.users as u', 'u.id', '=', 'l.user_id') ->where('l.user_id', $userId)->where('l.status', 'active')->where('p.party_type', 'person') ->whereNull('p.deleted_at')->where('l.valid_from', '<=', now()) ->where(fn ($q) => $q->whereNull('l.valid_until')->orWhere('l.valid_until', '>', now())) ->value('l.party_id'); return is_string($id) ? $id : null; } }