如何在带有原始查询的 Laravel 5 中使用分页
问题描述
我有一个简单的问题,但没有找到我需要的.
I have a simple question and I didn´t find what I need.
我需要计算商店列表的 t2 地理编码点之间的距离.我还需要为 WebService 分页.
I need to calculate the distance between t2 geocode points for a list of Stores. I also need it to be paginated for a WebService.
这可行,但结果中没有距离:
This works, but there is no distance in the result:
结果是:
但我需要这段代码工作:
But I need this code working:
这是结果:
我需要 next_page_url
和 prev_page_url
有什么想法吗?
推荐答案
在 Eloquent 模型上使用 selectRaw
方法.
Use the selectRaw
method on the Eloquent model.
在这种情况下,Laravel 会向数据库询问行的数量(使用 select count(*) as aggregate from stores
)以节省您的 RAM.
In that case Laravel asks the database for the amount of rows (using select count(*) as aggregate from stores
) which saves your RAM.
这篇关于如何在带有原始查询的 Laravel 5 中使用分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!