php - Laravel 一页一页分页问题

标签 php laravel

很抱歉,我的 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'));

}

在 Blade 页面中:

  <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

最佳答案

您的问题是您正在使用每个循环的当前索引 - 该索引始终在每个页面的 1-10 范围内(因为每个页面有 10 个元素)。

您需要获取当前正在使用的页面

$allapo->currentPage()

然后使用

获取每页的元素数量
$allapo->perPage()

将这两者相乘,它将成为分页的基数,这意味着您应该从此数字开始递增。

索引表应该是

{{ $allapo->currentPage() * $allapo->perPage() + $loop->index }}

而不是

{{ $loop->index+1 }}

然后,要修复标题编号(顶部的 10 和 6),请使用以下命令获取结果总数而不是页面计数

$allapo->total()

请参阅Laravel documentation更多细节。

关于php - Laravel 一页一页分页问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55571173/

相关文章:

javascript - google recaptcha V2 完成时自动发送表单

php - Laravel 5 时差

php - Laravel DB::select() 不返回 "correct"数据

php - Laravel Request::all() 不应该被静态调用

Laravel - 如何将 Active Directory 身份验证与用户身份验证结合起来

php - 具有多个值的广义选择查询

php - 我应该使用 Join 还是使用单独的查询

PHP 表单验证 - foreach

php - 将表从开发迁移到生产

Laravel Auth 因重复的用户电子邮件而失败