[英]Can't paginate data in Laravel
I've successfully retrieved data and displayed it in the list of table but my list is not having paginate我已成功检索数据并将其显示在表格列表中,但我的列表没有分页
I tried to display 15 data per page,but it displayed all data at once in the page.My data is coming from API .我试图每页显示 15 个数据,但它一次在页面中显示所有数据。我的数据来自 API。
My controller我的控制器
public function index()
{
$response = $this->client->get('getUserIndex')->getBody();
$content = json_decode($response->getContents(),true);
$collection = new \Illuminate\Support\Collection($content);
$total = count($collection['data']);
$paginationRecord = CollectionPaginate::paginate($collection, $total, 15);
return view('configuration.comuserprofiles.ComUserProfilesList', compact('paginationRecord'));
}
half of my table view我的表视图的一半
@foreach($paginationRecord as $i=>$user)
@foreach($user as $i => $u)
@php
$currentRecordno = 1;
// dd($u['irel__com_access_level']['ID']);
@endphp
<tr>
<td>{{ $currentRecordno + $i }}</td>
<td>{{ $u['ID'] }}</td>
<td>{{ $u['NICK_NAME'] }}</td>
<td>{{ $u['PWD_INVALID_HIT'] }}</td>
</tr>
@endforeach
my pagination blade我的分页刀片
<div class="row row-pagination">
<div class="col-sm-6 text-left">
<small class="text-muted inline m-t-sm m-b-sm"><font color="#00000f">{{ $paginationRecord->total() }} record/s found </font></small>
</div>
<div class="col-md-6 text-right text-center-xs">
<ul>
{{ $paginationRecord->links() }}
</ul>
</div>
</div>
I'm expecting to display 15 records per page我希望每页显示 15 条记录
Use take()
Collection's method to get specific number of elements使用
take()
集合的方法获取特定数量的元素
$paginationRecord = CollectionPaginate::paginate($collection->take(15), $total, 15);
You can also use forPage()
.您也可以使用
forPage()
。
$page = Illuminate\Pagination\Paginator::resolveCurrentPage() ?: 1;
$paginationRecord = new Illuminate\Pagination\LengthAwarePaginator($collection->forPage($page, 15), $total, 15, $page);
通过在控制器中的 $content 添加 ['data'] 已经解决了
$content = $content['data'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.