select('id', 'viewed') ->when(request()->has('product'), function ($query) { $query->whereTranslationLike('name', request('product') . '%'); }) ->when(request()->has('sku'), function ($query) { $query->where('sku', request('sku')); }) ->orderByDesc('viewed'); } }