【问题标题】:Add cursorPaginate to collection将 cursorPaginate 添加到集合
【发布时间】:2022-10-04 18:34:23
【问题描述】:

因此,我在 Laravel 中构建了一个非常详细的集合,以在我的前端工作的格式为我提供非常具体和干净的数据。现在,忘记这将是很多数据,我需要添加分页。因为这只是无限滚动,我想使用cursorPaginate

不幸的是,下面的代码不允许这样做。 Method Illuminate\Support\Collection::cursorPaginate does not exist的标准误

我将如何最好地重构它以给我所需的数据并给我 cursorPaginate?我完全愿意改变其中的一些,我只是不知道从哪里开始最好。

提前致谢!

return Activity::get()->groupBy('batch_uuid')->map(function ($batch) {
                return [
                    'description' => $batch->first()->description,
                    'uuid' => $batch->first()->batch_uuid,
                    'event' => $batch->first()->event,
                    'created_at' => $batch->first()->created_at,
                    'subject' => $batch->first()->subject_type::find($batch->first()->subject_id),
                    'activities' => $batch->map(function ($activity) {
                        return [
                            'item' => $activity->causer_type::find($activity->causer_id),
                        ];
                    }),
                ];
            })->sortByDesc('created_at')->values();  
    ```

【问题讨论】:

    标签: laravel


    【解决方案1】:

    你应该从 Laravel Daily 观看 this video。他使用的本视频中提到的第一种方法LengthAwarePaginator但你可以试试光标分页器为你的目的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      • 1970-01-01
      • 2016-07-27
      • 2010-12-01
      相关资源
      最近更新 更多