سلام دوستان
برای اینکه بخوام اون دکمه های قبل و بعد رو با تموم کاراییشون نمایش بدم باید چیکار کنم؟
$admins = Admin::paginate(5);
return response([
'status' => 200,
'message' => 'List of admins',
'admins' => $admins,
'meta' => [
'count' => $admins->count(),
'nextPageUrl' => $admins->nextPageUrl(),
'previousPageUrl' => $admins->previousPageUrl(),
'perPage' => $admins->perPage(),
'total' => $admins->total(),
'lastItem' => $admins->lastItem(),
]
]);
ممنون میشم راهنمایی کنید
سلام شما اگه به این روش عمل کنید
return response()->json([
'users' => User::paginate(5)
]);
پاسخش به این صورت است
میتونید از کلید آرایه links برای نمایش لینکهای صفحه بندی استفاده کنید.
با یک حلقه foreach این لیستو پیمایش کنید و با توجه به کلیدهای url - label - active گزینه ای مربوطه رو فعال یا غیر فعال کنید
{
"users": {
"current_page": 1,
"data": [
{
"id": 1,
"name": "Miss Ebba Hansen I",
"email": "linnea.huel@example.net",
"age": null,
"status": 3,
"isAgencyEmail": 0,
"gmail_access_token": null,
"email_verified_at": "2022-04-03T04:59:02.000000Z",
"created_at": "2022-04-03T04:59:03.000000Z",
"updated_at": "2022-04-03T04:59:03.000000Z"
},
{
"id": 2,
"name": "Prof. Henri Rau",
"email": "rmarks@example.com",
"age": null,
"status": 3,
"isAgencyEmail": 0,
"gmail_access_token": null,
"email_verified_at": "2022-04-03T04:59:03.000000Z",
"created_at": "2022-04-03T04:59:03.000000Z",
"updated_at": "2022-04-03T04:59:03.000000Z"
}
],
"first_page_url": "http://127.0.0.1:8000/users?page=1",
"from": 1,
"last_page": 15,
"last_page_url": "http://127.0.0.1:8000/users?page=15",
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=1",
"label": "1",
"active": true
},
{
"url": "http://127.0.0.1:8000/users?page=2",
"label": "2",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=3",
"label": "3",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=4",
"label": "4",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=5",
"label": "5",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=6",
"label": "6",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=7",
"label": "7",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=8",
"label": "8",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=9",
"label": "9",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=10",
"label": "10",
"active": false
},
{
"url": null,
"label": "...",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=14",
"label": "14",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=15",
"label": "15",
"active": false
},
{
"url": "http://127.0.0.1:8000/users?page=2",
"label": "Next »",
"active": false
}
],
"next_page_url": "http://127.0.0.1:8000/users?page=2",
"path": "http://127.0.0.1:8000/users",
"per_page": 2,
"prev_page_url": null,
"to": 2,
"total": 30
}
}
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟