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
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire