我在应用程序中的查询中使用 Laravel 的 Pagination 功能,该功能作为 JSON 响应返回到我的前端(它是 Laravel Rest API)
/**
* Applications
*/
public function getApplications()
{
$applications = Application::orderBy('created_at', 'desc')
->paginate(25);
foreach ($applications as $key => $applicant) {
try {
$applications[$key]['data'] = json_decode($applicant['data']);
} catch (\Exception $e) { }
}
return $applications;
}
/**
* All applications
*
* @param Request $request
*/
public function applications(Request $request)
{
try {
// daily graphs
$applications = $this->getApplications();
// not set or nothing to report
if (!$applications) {
return response()->json([
'success' => false,
'msg' => 'No applications found, check back in a few minutes',
], 422);
}
// return the response
return response()->json([
'success' => true,
'msg' => 'Icicle applications',
'applications' => $applications ?? null
], 200);
} catch (\Exception $e) {
// return default template
return response()->json([
'success' => false,
'msg' => 'We were unable to load applications right now',
], 422);
}
}
但是,页面上显示的默认链接数量从 1 开始,然后增加到 10,这对我来说太多了,我想减少它们以显示更少的链接,例如,1 到 5。
我似乎无法在这里找到任何有关如何配置分页器的文档,并且由于它不是视图,因此如何减少链接?我是否缺少一些配置?