You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 8结合Bootstrap分页无法跳转至最后一页及倒数第三页问题

Laravel 8 Bootstrap分页无法跳转至最后一页问题

此前我开发过一个Laravel 8应用,使用Bootstrap分页功能,当时数据库只有约40条数据,分页运行正常。现在我新开发了一个应用,数据库内有300020条数据,分页页数相较之前更多,但出现了无法跳转至最后一页的问题,仅能跳转至页码更小的页面,效果如下图:
分页展示截图

我不清楚为什么分页组件不允许我跳转至最后一页以及倒数第三页,异常现象截图如下:
分页跳转异常截图

我使用的是links()方法实现分页渲染,前端模板代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Employees</title>
    <link href="{{ mix('css/app.css') }}" rel="stylesheet" type="text/css" />

</head>
<body>
    {{ $employees->total() }}
    <div class="container">
        <div class="row">
            <div class="col-sm-4"></div>
            <div class="col-sm-4">
                <table class="table">
                    <thead class="thead-dark">
                        <th>Emp_no</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Hire Date</th>
                    </thead>
                    <tbody>
                        @foreach($employees as $employee)
                            <tr>
                                <td>{{ $employee->emp_no }}</td>
                                <td>{{ $employee->first_name }}</td>
                                <td>{{ $employee->last_name }}</td>
                                <td>{{ $employee->hire_date }}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
                <hr>
                {{ $employees->links() }}
            </div>
            <div class="col-sm-4"></div>
        </div>
    </div>
    <!-- Bootstrap JS, jquery y popper compiled -->
    <script src="{{ mix('js/app.js') }}" type="text/javascript"></script>
</body>
</html>

控制器代码如下:

class EmployeeController extends Controller
{
    public function index() {
        $employees = Employee::query()->Paginate(5);

        return view('employee.index', compact('employees'));
    }
}

模型代码如下(我向数据库导入了一张现成的业务表):

class Employee extends Model
{
    use HasFactory;

    protected $table = 'employees';
    protected $primaryKey = 'emp_no';
}

我习惯在有数千条数据的场景下测试应用,如果大家有解决这个问题的思路,麻烦告知我,非常感谢。

内容的提问来源于stack exchange,提问作者Freddy Daniel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 17:54:03