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

i want to use order By for above code and also it just group By 5 records, but i want a records like firstly it should group By and then apply pagination.

1 Answers1

0

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.

check here: https://laravel.com/docs/5.3/pagination#basic-usage

check this for order by : https://stackoverflow.com/a/19885982/2815635

Community
  • 1
  • 1
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109