Two things to note regarding @bobbybouwmann answer.
For the proposed solution to work, you need to have a Cup model. Else, you would have to use \DB::table('cups') instead.
Also, you would probably need to have a dynamic array of IDs in your whereIn clause. If you do, you can achieve it by passing your array variable to the use statement of the anonymous subquery function:
Cup::whereIn('id', function ($query) use ($categoryIds) {
$query->select('cup_id')->from('products')->whereIn('category_id', $categoryIds)->groupBy('cup_id');
})->get();
P.S. You don't need the use statement with $this, so if you get your category IDs with a function/relation of the current class, you can omit it.