Laravel - 分页和获取()
问题描述
使用下面的代码,我想要的是对我创建的查询进行分页.但是,当我尝试在 get 之后添加分页时,它会引发错误.我想保持 get 因为我想限制在 $fields 上设置的列.对这件事进行分页应该是什么更好的主意?或者什么是获取和限制列的好替代品?
With the code below, what I wanted was paginate the query I created. But, when I try to add paginate after get, it throws an error. I wanted to remain get since I want to limit to columns that was set on $fields. What would should be the better idea to paginate this thing? or what's a good substitute for get and limit the columns?
我尝试了什么:
我的控制器的一部分:
}
推荐答案
如果你看看 方法签名 你会看到 paginate 接收到第二个参数 $columns.所以你的解决方案是使用
If you look at the method signature you will see that paginate receives a second argument, $columns. So your solution would be to use
此外,您可以通过稍微改变一些东西来清理您的控制器:
Furthermore, you can clean up your controller by changing things slightly:
这篇关于Laravel - 分页和获取()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!