// From the Resource for ASelectFilter::make('thename')->multiple()->options($theOptionsArray)->query( functions (Builder $query, array $data) { if(count($data['values']) != 0) $query->whereHas('relationBetweenA&B', fn (Builder $query) => $query->whereIn('columnOnB', $data['values'])); })