Is there any way to display pagination incrementing id in Laravel which is sorted inside a Resource class?
I know I can do this easily in frontend, but I want to achieve this in backend.
This is my code in my controller and resource class.
//controller
$materials = MaterialResource::collection($items->paginate(6)->appends($request->query()));
return inertia('Admin/Material/Index', compact('training', 'materials'));
//MaterialResource
public function toArray($request)
{
return [
'id' => $this->id, //this can be 5,4,2,1 (order by title)
'title' => $this->title,
'tags' => $this->tags,
'paginate_id' => 0, //this should be current_page + 1,2,3,4,5....
];
}