GodziLaravel's avatar

How to change data in pagination result ?

Hello ,

I would like to change data content in this pagination results!

        if ($id != auth()->user()->id) return response()->json(['error' => 'Not authorized.'], 403);
        $competenceLogs = CompetenceLog::where('member_id', '=', $id)
        ->orderby('created_at','DESC')->paginate(15);

        return $competenceLogs;

this returns :

{
  "current_page": 1,
  "data": [
    {
      "id": 53,
...

  ],
  "first_page_url": "http://mostafa.o.com/api/competence-logs/532?page=1",
  "from": 1,
  "last_page": 3,
  "last_page_url": "http://mostafa.o.com/api/competence-logs/532?page=3",
  "next_page_url": "http://mostafa.o.com/api/competence-logs/532?page=2",
  "path": "http://mostafa.o.com/api/competence-logs/532",
  "per_page": 15,
  "prev_page_url": null,
  "to": 15,
  "total": 32
}

which is normal !

now I would like to change the data content and "regroup it " with this following code :

        return $competenceLogs->get()->groupBy(function ($item) {
            return $item->created_at->toDateString();
        })->map(function ($group) {
            return $group->groupBy(function ($item) {
                return ($item->wheel_id != null) ? wheel::find($item->wheel_id)->name : 'evaluation';
            });
       });

How to do this ?

0 likes
1 reply

Please or to participate in this conversation.