对不起,我的laravel分页有问题,例如,一页一页地给我,在我的表16行中,我进行分页(10),第一页中分页给我从1到10,然后在从1到6的第二页中,我希望从1到10的正常分页以及从11到16的任何帮助,请
public function allappointmnts(){
$allapo=DB::table('bookappoitments')->orderBy('times.id')
->join('users','bookappoitments.users_id','users.id')
->join('times','bookappoitments.times_id','times.id')
->join('dates','bookappoitments.Dates_id','dates.id')
->paginate(10);
return view('admin.Managers.allappoinments',compact('allapo'));
}
在刀片页面中:
<div class="text-center">
{!! $allapo->links(); !!}
</div>
表格:
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Time</th>
<th>Employee</th>
<th>Name</th>
<th>Email</th>
<th>Company</th>
<th>Phone</th>
<th>Location</th>
<th>Remarks</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<tr>
@foreach($allapo as $Appointments)
<td>{{ $loop->index+1 }}</td>
<td>{{ $Appointments->Dates }}</td>
<td>{{ $Appointments->from_to }}</td>
<td>{{ $Appointments->name }}</td>
<td>{{ $Appointments->gustname }}</td>
<td>{{ $Appointments->gustemail }}</td>
<td>{{ $Appointments->gustcompany }}</td>
<td>{{ $Appointments->gustphone }}</td>
<td>{{ $Appointments->Location }}</td>
<td>{{ $Appointments->Remarks }}</td>
<td>
<a class="btn btn-success btn-mini deleteRecord " href="{{url('showbymanagment',$Appointments->id)}}">Show</a>
</td>
</tr>
@endforeach
答案 0 :(得分:2)
您的问题是您正在使用每个循环的当前索引-始终在每页1-10的范围内(因为每页有10个元素)。
您需要使用
来获取当前正在使用的页面$allapo->currentPage()
然后使用
获取每页获得的元素数$allapo->perPage()
将这两个数相乘,它将是您的分页的基数,这意味着您应该从中增加该数字。
索引表应该是
{{ $allapo->currentPage() * $allapo->perPage() + $loop->index }}
代替
{{ $loop->index+1 }}
然后,要固定标题编号(在顶部的10和6),请获取结果总数,而不是使用
$allapo->total()
有关更多详细信息,请参见Laravel documentation。
答案 1 :(得分:1)
尝试以下代码:
<?php $i = $lists->perPage() * ($lists->currentPage() - 1); ?>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Time</th>
<th>Employee</th>
<th>Name</th>
<th>Email</th>
<th>Company</th>
<th>Phone</th>
<th>Location</th>
<th>Remarks</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<tr>
@foreach($allapo as $Appointments)
<td><?php $i++; ?>{{ $i }} </td>
<td>{{ $Appointments->Dates }}</td>
<td>{{ $Appointments->from_to }}</td>
<td>{{ $Appointments->name }}</td>
<td>{{ $Appointments->gustname }}</td>
<td>{{ $Appointments->gustemail }}</td>
<td>{{ $Appointments->gustcompany }}</td>
<td>{{ $Appointments->gustphone }}</td>
<td>{{ $Appointments->Location }}</td>
<td>{{ $Appointments->Remarks }}</td>
<td><a class="btn btn-success btn-mini deleteRecord " href="
{{url('showbymanagment',$Appointments->id)}}">Show</a></td>
</tr>
@endforeach
答案 2 :(得分:1)
不确定,但是您需要编写某种函数来解决此问题。
基本上,您需要这样做:
function correct_pagination_numbers($cp, $pp, $counter)
{
$c = (($pp * $cp) + $counter) - $pp;
return $c;
}
然后,您可以像这样在视图中调用该函数:
<td>{{ correct_pagination_numbers($allapo->currentPage(), $allapo->perPage(), $loop->index) }}</td>
这可能是在帮助程序文件中执行此操作的最佳解决方案。如果您不知道如何创建帮助文件并自动加载,可以查看here。
答案 3 :(得分:0)
尝试一下
@foreach($ allapo as $ key => $ Appointments)
{{$ key + $ allapo-> firstItem()}}
@endforeach
答案 4 :(得分:-3)
要查看正确的数字,请更改行
<td>{{ $loop->index+1 }}</td>
收件人:
<td>{{ ($allapo->currentPage() - 1) * $allapo->perPage() + $loop->iteration }} <td>