我如何对 Laravel 集合进行分页? [英] How can i paginate laravel collection?
本文介绍了我如何对 Laravel 集合进行分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我尝试分页的方式:
here is how i trying to paginate:
$posts = Post::all()->sortByDesc("created_at")->pagination(1);
但我收到此错误:
方法 IlluminateDatabaseEloquentCollection::pagination 不存在.
Method IlluminateDatabaseEloquentCollection::pagination does not exist.
推荐答案
这是因为 paginate
是 Builder
方法,而不是集合.
It is because paginate
is Builder
method, not collection.
您需要手动创建分页器,这里如何描述 - https://laravel.com/docs/8.x/pagination#manually-creating-a-paginator
You need to create paginator manually, how described here - https://laravel.com/docs/8.x/pagination#manually-creating-a-paginator
这篇关于我如何对 Laravel 集合进行分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文