Php Laravel:分页仅返回第一个块
在我的Laravel应用程序中,我通过AJAX请求拉入分页数据。这对于第一个块很有效。但是,对于以下内容,它只传递一列(id) 有什么问题 有关守则:Php Laravel:分页仅返回第一个块,php,laravel,pagination,laravel-5.4,Php,Laravel,Pagination,Laravel 5.4,在我的Laravel应用程序中,我通过AJAX请求拉入分页数据。这对于第一个块很有效。但是,对于以下内容,它只传递一列(id) 有什么问题 有关守则: Route::get('contacts', function (Request $request) { return buildQuery($request, User::class)->simplePaginate(50); }); function buildQuery(Request $request, $model) {
Route::get('contacts', function (Request $request) {
return buildQuery($request, User::class)->simplePaginate(50);
});
function buildQuery(Request $request, $model) {
$query = DB::table('users')->select('id as ID');
$properties = $request->all();
$searchString = "";
if (in_array('q', array_keys($properties)) && $properties['q']) {
$searchString = $properties['q'];
$query->orWhere('id', 'like', '%'.$searchString.'%');
}
foreach ($properties as $property => $value) {
if ($property == "id" || $property == "q")
continue;
if (in_array($property, array_keys($model::$labels))) {
$query->addSelect($property.' as '.$model::$labels[$property]);
if ($value == "desc" || $value == "asc")
$query->orderBy($property, $value);
if ($searchString)
$query->orWhere($property, 'like', '%'.$searchString.'%');
}
}
return $query;
}
这是因为查询参数没有附加到后续分页请求中 将路由内的逻辑更新为:
Route::get('contacts', function (Request $request) {
return buildQuery($request, User::class)->paginate(50)->appends($request->all());
});
或
导致:BadMethodCallException:方法附加不存在。好的,我的错误。它与LengthAwarePaginator一起工作。如果需要它进行简单分页,请在从查询生成链接时使用查询返回的结果的附录。相同错误。调用的对象append是一个AbstractPaginatorok,我输入错误。它应该是带有“s”的“附加”。它应该对paginate和simplePaginate方法都有效。你应该得到这个勾号^^
Route::get('contacts', function (Request $request) {
return buildQuery($request, User::class)->simplePaginate(50)->appends($request->all());
});