我正在尝试在 Laravel 中对分页查询结果进行排序。我需要通过将所有内容的末尾降到我的分页变量来进行排序。
例子:
//get some data attach to variable
$variable = DB::table('exampletable')
->where('id',$somevariable)
->select('id','name')
->paginate(10);
//this function will send the variable and attach **total** on each object
$variable = $this->aFunction($variable);
//What I am trying to do, THIS is where I have to sort in the data flow
$variable->sortBy('total', 'desc');
//return data in json format
return response()->json($variable);
Run Code Online (Sandbox Code Playgroud)
我试过像上面说的那样对它进行排序,但我最终得到的变量只是在每个段/对象上都有名称。我已经尝试过,这是我不断得到的结果:
{
"0":{
"id": "1",
"name": "somename",
"total": "15",
},
"1":{
"id": "2",
"name": "somename2",
"total": "100",
},
"2":{
"id": "3",
"name": "somename5", …Run Code Online (Sandbox Code Playgroud)