Arrays 无法对laravel中的数组对象使用分页()
我正在用Laravel 5.7构建一个数组。我想对它分页,但由于数组特性,它会出错。我该怎么办 在MyController.php中:Arrays 无法对laravel中的数组对象使用分页(),arrays,laravel,pagination,Arrays,Laravel,Pagination,我正在用Laravel 5.7构建一个数组。我想对它分页,但由于数组特性,它会出错。我该怎么办 在MyController.php中: $result = array(); foreach ($sameDateMatches as $key => $date) { array_push($result, [ 'date' => $key, 'day_of_week' => getDayOfWeek($key), 'matches' => $date
$result = array();
foreach ($sameDateMatches as $key => $date) {
array_push($result, [
'date' => $key,
'day_of_week' => getDayOfWeek($key),
'matches' => $date,
]);
}
if (!empty($_GET['page'])) {
$result = $result->paginate(10);
$pagination = $result;
} else {
$result = $result;
$pagination = null;
}
return returnSuccessfulResponse(
trans('api.response.successful.show'),
[
'Scheduled Matches' => $result,
],
$pagination
);
对数组上的成员函数paginate()的调用
只能对的实例使用
paginate
相反,如果需要对数组进行“分页”,可以使用
只能对的实例使用
paginate
相反,如果需要对数组进行“分页”,可以使用
我使用
make()
和LengthAwarePaginator
解决了我的问题,如下所示:
if (!empty($_GET['page'])) {
$per_page = !empty($_GET['per_page']) ? $_GET['per_page'] : 10;
$page = $_GET['page'];
$result = $result instanceof Collection ? $result : Collection::make($result);
$result = new LengthAwarePaginator(
$result->forPage($page, $per_page)->values(),
$result->count(),
$per_page,
$page,
['path' => request()->url()]
);
$pagination = $result;
} else {
$pagination = null;
}
我使用
make()
和LengthAwarePaginator
解决了我的问题,如下所示:
if (!empty($_GET['page'])) {
$per_page = !empty($_GET['per_page']) ? $_GET['per_page'] : 10;
$page = $_GET['page'];
$result = $result instanceof Collection ? $result : Collection::make($result);
$result = new LengthAwarePaginator(
$result->forPage($page, $per_page)->values(),
$result->count(),
$per_page,
$page,
['path' => request()->url()]
);
$pagination = $result;
} else {
$pagination = null;
}
错误信息是什么?或者错误提示了什么?
调用数组上的成员函数paginate()
不能在数组上使用laravel的paginate,只能在有说服力的模型/对象上使用它错误消息是什么?或者错误提示了什么?调用数组上的成员函数paginate()
不能在数组上使用laravel的paginate,只能在有说服力的模型/对象上使用它