如何在 groupby 和 orderby 子句中使用分页来按年获取 laravel 中的记录

how to use pagination in groupby & orderby clause for fetching records in laravel by year wise

$newsYearCount = news::paginate(5)->groupBy(function($date) {
                      return Carbon::parse($date->created_at)->format('Y'); //
                  });

我想对上面的代码使用 order By,它也只是按 5 条记录分组,但我想要一个记录,首先它应该按分组,然后应用分页。

Currently, pagination operations that use a groupBy statement cannot be executed efficiently by Laravel. If you need to use a groupBy with a paginated result set, it is recommended that you query the database and create a paginator manually.

在此处查看:https://laravel.com/docs/5.3/pagination#basic-usage

检查此订单的顺序: