use Illuminate\Pagination\LengthAwarePaginator;
$paginate = $model->paginate(25, ['*'], 'page', $page);
$paginate->setCollection($paginate->getCollection()->map(function (Customer $customer) {
$data = $customer->toArray();
$data['mobile'] = getHiddenMobile($data['mobile']);
return $data;
}));
// 每頁顯示數量固定25條
// 強制最多隻能顯示5頁,共125條資料
// 超過部分直接返回空資料
$new = new LengthAwarePaginator(
$page > 5 ? [] : $paginate->items(),
min($paginate->total(), 125),
$paginate->perPage(),
$paginate->currentPage(),
$paginate->getOptions()
);
本作品採用《CC 協議》,轉載必須註明作者和本文連結