Level 80
@eddy1992 You’re better off appending your query string to the paginator, rather than trying to override the path (which is why you’re getting two ?s in your URLs):
$products = Product::whereHas('categories', function ($query) use ($categoryIds) {
$query->whereIn('category_id', $categoryIds);
})->paginate(16)->appendArray($request->query());