php - 如何在分页对象上使用 ->unique() 来删除 laravel 中的所有重复项
问题描述
我的 laravel 中有一个分页集合,如下所示:
$data = QueryBuilder::for(Accommodation::class)
->allowedFilters([
AllowedFilter::scope('bed_count'),
AllowedFilter::scope('filter_price'),
AllowedFilter::scope('filter_date'),
AllowedFilter::scope('discounts'),
AllowedFilter::scope('name'),
AllowedFilter::exact('grade_stars'),
AllowedFilter::exact('city_id'),
AllowedFilter::exact('is_recommended'),
AllowedFilter::exact('accommodation_type_id'),
AllowedFilter::scope('accommodation_facility')
// 'name',
])
->allowedAppends(['cheapestroom'])
->allowedIncludes(['gallery','city','accommodationRooms','accommodationRooms.roomPricingHistorySearch','discounts','prices'])
->allowedSorts([
AllowedSort::custom('discount', new DiscountSort() ,'amount'),
AllowedSort::custom('price', new PriceSort() ,'price'),
])
->paginate(10);
现在,如果我->unique
在我的上使用$data
它只会返回我的第 10 个结果,不显示其他结果我不想从我的集合中删除分页,因为它会像 5k 记录一样调用很重的对象,我不想使用 join as只要它对我造成其他问题,所以我的问题是:是否有可能在 laravel 或资源中唯一的分页对象?
解决方案
推荐阅读
- sql - 不理解“从 TABLE_NAME 中选择 @variable_name、column1、column2”类型的 sybase 查询
- javascript - d3js v5 + topojson v3 以缩放为中心的方形质心
- postgresql - Scala Play 将存储库注入控制器
- html - HTML 5 历史 - 打开/重新加载子页面
- javascript - NativeScript 核心 TextField onTextChange 在模型和外部模型中
- geometry - 球体相交:从相交圆的给定半径获取球体之间的距离
- javascript - 添加“For Loop”而不是“forEach”
- c# - xaml 中 Observable 集合的嵌套数据绑定
- azure - 逻辑应用 CosmosDb 存储过程连接器返回未经授权
- ruby-on-rails - before_filter 出现故障,在 dev 和 staging 环境中运行良好。但不适用于 qa 环境