【发布时间】:2018-04-26 03:15:45
【问题描述】:
我想为我的选择查询添加 laravel 分页器: 以下查询工作正常,但无法添加 laravel 分页器。
$results = DB::select('SELECT
distances.*
FROM
(SELECT
( 6371 * acos( cos( radians(23.0376279 ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(72.5102283 ) ) + sin( radians(23.0376279 ) ) * sin( radians( latitude ) ) ) ) AS distance,
shopdatabase.shop_product.stock,
shopdatabase.shop_product.price AS price,
shopdatabase.shops.id AS shopId,
shopdatabase.product.name AS name,
shopdatabase.product.id AS productId,
shopdatabase.shops.name AS shopName,
shopdatabase.shop_product.status,
shopdatabase.product_image.title AS image,
shopdatabase.product_meta.metaValue AS sourceDetails,
shopdatabase.product.sourceUrl
FROM
shopdatabase.shop_product
INNER JOIN shopdatabase.shops
ON shopdatabase.shop_product.shopId = shopdatabase.shops.id
INNER JOIN shopdatabase.product
ON shopdatabase.shop_product.productId = shopdatabase.product.id
INNER JOIN shopdatabase.product_image
ON shopdatabase.shop_product.productId = shopdatabase.product_image.productId
INNER JOIN shopdatabase.product_meta
ON shopdatabase.shop_product.productId = shopdatabase.product_meta.productId
WHERE
shopdatabase.shop_product.status = "active") distances
WHERE
distance < 20
ORDER BY
distance ASC');
或者你能告诉我如何用 Eloquent 编写这个选择查询吗? 如果我们可以用 Eloquent 编写上面的代码,那就太好了。
【问题讨论】:
-
您的代码不可读。首先 - 使用雄辩的关系。
标签: laravel pagination eloquent