LengthAwarePaginatorからJSONを返しますが、JSONのdata
プロパティは配列ではありません。私はそれを配列にする必要があります。何か案は?Laravel 5:LengthAwarePaginatorが配列ではなくJSONを返しました
// grab query parameters
$pageNumber = $request->input('page');
$pageSize = $request->input('pageSize');
// if query params do not exist call with defaults
if(!$pageNumber) {
$pageNumber = 1;
}
if(!$pageSize) {
$pageSize = 5;
}
$offset = ($pageNumber * $pageSize) - $pageSize;
// slice full array data based on page number and page size
$itemsForCurrentPage = array_slice($arrayOfData, $offset, $pageSize, true);
return new LengthAwarePaginator($itemsForCurrentPage, count($this->orgUsers), $pageSize, $pageNumber);
返されるデータ:
{
"total": 30,
"per_page": 5,
"current_page": 2,
"last_page": 6,
"next_page_url": "/?page=3",
"prev_page_url": "/?page=1",
"from": 6,
"to": 10,
"data": {
"5": {
"userId": "564110eadcb39832268ea873",
"email": "[email protected]",
"isActive": true,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg",
"permissionType": "dsdfgdfg"
},
"6": {
"userId": "564110ea2169bc358a3b65c2",
"email": "[email protected]",
"isActive": false,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg",
"permissionType": "dsdfgdfg"
},
"7": {
"userId": "564110eaee662f30c4bd6772",
"email": "[email protected]",
"isActive": true,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg",
"permissionType": "dsdfgdfg"
},
"8": {
"userId": "dsdfgdfg",
"email": "[email protected]",
"isActive": true,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg"
},
"9": {
"userId": "564110eaf9526eb5ddd673a4",
"email": "[email protected]",
"isActive": true,
"firstName": "dsdfgdfg",
"lastName": "dsdfgdfg"
}
}
}
TIA
'json_decode'を使ってjsonを配列に変換するだけです。 –
の' array_slice'の 'true'から' false'への変更 –