Ребята всем привет. Подскажите корректно ли будет использовать запрос так:
$productsCatalogAll = Product::query()->whereHas('subcategories', function($builder) use ($subcategoryId){
$builder->where('subcategory_id', $subcategoryId->id);
})->when($request->is('expensive'), function ($expensive){
$expensive->orderBy('price', 'desc');
})->when($request->is('cheap'), function ($cheap){
$cheap->orderBy('price','asc');
})->when($request->is('newItem'), function ($newItem){
$newItem->where('is_new', 1);
})->paginate(config('setting.paginate'));