Presumably these are filtering a top level collection of data. Once you apply these filters you can pluck these filter values from that other filtered collection and then filter down these lists. I appreciate it sounds complicated but hopefully this example explains.
$users = User::query()
->where('group', 'g1')
->get()
$groups = Group::query()
->whereIn('id', $users->pluck('group')->unique())
->get()
Something like this, adapt the actual queries for relationships accordingly