【发布时间】:2022-01-05 10:40:04
【问题描述】:
我正在使用带有 vuejs 的“element-ui”表,分页,列出所有内容都可以,但是它在排序过程中执行,但由于我的 laravel 查询,它无法按 asc 或 desc 排序。 laravel query 可以保存查询参数,如何在 laravel 中编写,提前为您提供帮助。
回复时请注意我是 laravel 新手
查询参数
page: 1 sort: email|asc
http://localhost:3000/user?page=1&sort=name%7Cdesc
http://localhost:3000/user?page=1&sort=email%7Casc
public function getUser(Request $request)
{
$users = User::paginate(10);
return response()->json($users);
}
{
"current_page": 1,
"data": [
{
"id": 1,
"name": "serdar",
"email": "serdar@gmail.com",
"email_verified_at": null,
"created_at": "2022-01-03T10:11:46.000000Z",
"updated_at": "2022-01-03T10:11:46.000000Z"
},
{
"id": 2,
"name": "Nettie Muller",
"email": "wilderman.filiberto@example.net",
"email_verified_at": "2022-01-05T09:34:01.000000Z",
"created_at": "2022-01-05T09:34:02.000000Z",
"updated_at": "2022-01-05T09:34:02.000000Z"
},
{
"id": 3,
"name": "Bridgette Blanda",
"email": "melba41@example.net",
"email_verified_at": "2022-01-05T09:34:01.000000Z",
"created_at": "2022-01-05T09:34:02.000000Z",
"updated_at": "2022-01-05T09:34:02.000000Z"
},
{
"id": 4,
"name": "Braden Marvin",
"email": "van.kerluke@example.com",
"email_verified_at": "2022-01-05T09:34:01.000000Z",
"created_at": "2022-01-05T09:34:02.000000Z",
"updated_at": "2022-01-05T09:34:02.000000Z"
},
{
"id": 5,
"name": "Donna Gutmann",
"email": "homenick.rene@example.net",
"email_verified_at": "2022-01-05T09:34:01.000000Z",
"created_at": "2022-01-05T09:34:02.000000Z",
"updated_at": "2022-01-05T09:34:02.000000Z"
},
{
"id": 6,
"name": "Ms. Viola Ullrich PhD",
"email": "okeefe.loma@example.net",
"email_verified_at": "2022-01-05T09:34:01.000000Z",
"created_at": "2022-01-05T09:34:02.000000Z",
"updated_at": "2022-01-05T09:34:02.000000Z"
},
{
"id": 7,
"name": "Christy Lakin",
"email": "turcotte.asha@example.com",
"email_verified_at": "2022-01-05T09:34:01.000000Z",
"created_at": "2022-01-05T09:34:02.000000Z",
"updated_at": "2022-01-05T09:34:02.000000Z"
},
{
"id": 8,
"name": "Creola Sporer",
"email": "smcdermott@example.org",
"email_verified_at": "2022-01-05T09:34:01.000000Z",
"created_at": "2022-01-05T09:34:02.000000Z",
"updated_at": "2022-01-05T09:34:02.000000Z"
},
{
"id": 9,
"name": "Ms. Kyra Glover MD",
"email": "margot.labadie@example.org",
"email_verified_at": "2022-01-05T09:34:01.000000Z",
"created_at": "2022-01-05T09:34:02.000000Z",
"updated_at": "2022-01-05T09:34:02.000000Z"
},
{
"id": 10,
"name": "Catherine Denesik MD",
"email": "malachi.deckow@example.net",
"email_verified_at": "2022-01-05T09:34:01.000000Z",
"created_at": "2022-01-05T09:34:02.000000Z",
"updated_at": "2022-01-05T09:34:02.000000Z"
}
],
"first_page_url": "http://kelebek.localhost/kasalar?page=1",
"from": 1,
"last_page": 11,
"last_page_url": "http://kelebek.localhost/kasalar?page=11",
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=1",
"label": "1",
"active": true
},
{
"url": "http://kelebek.localhost/kasalar?page=2",
"label": "2",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=3",
"label": "3",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=4",
"label": "4",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=5",
"label": "5",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=6",
"label": "6",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=7",
"label": "7",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=8",
"label": "8",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=9",
"label": "9",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=10",
"label": "10",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=11",
"label": "11",
"active": false
},
{
"url": "http://kelebek.localhost/kasalar?page=2",
"label": "Next »",
"active": false
}
],
"next_page_url": "http://kelebek.localhost/kasalar?page=2",
"path": "http://kelebek.localhost/kasalar",
"per_page": 10,
"prev_page_url": null,
"to": 10,
"total": 101
}
【问题讨论】: