try to get response json ,Laravel Pagination has missing meta and links with API resource

Trying

     $questions=TheQuestion::paginate(5);
return $this->successResponce(TheQuestionResource::collection($questions),'','');

{ success: true,data: [{},{},{},{},{}],tag: "",message: ""}

public function successResponce($data,$tag,$message)
{


return response()->json([
'success' => true,
'data' => $data,
'tag'=>$tag,
'message' => $message,
]);


}

API Resource is working fine but pagination data like current_page,total... is not showing. But When returning without JSON Response all things are coming

     $questions=TheQuestion::paginate(5);
return TheQuestionResource::collection($questions);
{
data: [],
links: {
first: "http://localhost:8000/api/v1/admin/question/management/show/%7B%7D?page=1",
last: "http://localhost:8000/api/v1/admin/question/management/show/%7B%7D?page=3",
prev: null,
next: "http://localhost:8000/api/v1/admin/question/management/show/%7B%7D?page=2"
},
meta: {
current_page: 1,
from: 1,
last_page: 3,
path: "http://localhost:8000/api/v1/admin/question/management/show/%7B%7D",
per_page: 5,
to: 5,
total: 11
}
}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2RvuuvH
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time