为什么 Laravel paginate() 没有按预期工作但 simplePaginate() 可以?

Why is Laravel paginate() not working as expected but simplePaginate() does?

我有一个名为 Conversation 的模型。我想通过分页显示视图中的所有行。我知道使用 paginate() 方法或 simplePaginate() 方法对结果进行分页。

在我的例子中,paginate()simplePaginate() 都按预期对结果进行了分页。我想在我的 blade 文件中显示分页链接。我也知道links()方法是用来做的

但问题是当我使用paginate()时,links()方法根本不起作用。当我使用 simplePaginate() 时它起作用了。我不想使用 simplePaginate(),因为它只显示 previousnext 链接。

这是我正在使用的最小代码:

web.php

Route::get('/conversations', 'RouteController@conversations')->name('conversations');

RouteController.php

class RouteController extends Controller {

    public function conversations(Request $request) {
        $conversations = Conversation::paginate(10);
        return view('conversations')->with('conversations', $conversations);

        // I also tried return view('conversations', compact('conversations));
    }
}

conversations.blade.php

..
<div>
    {{ $conversations->links() }}
</div>
..

我阅读了文档,代码中的一切似乎都很好。有趣的是,它在我离开的前一天还在工作!

我不明白为什么会这样? 这是预期的行为吗?或者我遗漏了什么?

Laravel 分页供应商资源

php artisan vendor:publish --tag=laravel-pagination

此外,无论您使用任何需要配置资源的软件包

datatables
datatables-buttons
datatables-fractal
datatables-html
laravel-errors
laravel-mail
laravel-notifications
laravel-pagination

只需键入此 php artisan vendor:publish 即可获取您需要发布的所有默认供应商。