As far as I know you can't paginate raw query, here's why:
$result = DB::select($sql);
$result
here will have the array type and paginate()
is the method from the IlluminateDatabaseQueryBuilder
class.
Your case can be performed this way:
$items = DB::table('team')
->selectRaw('SELECT *,earth_distance(ll_to_earth(team.lat, team.lng), ll_to_earth(23.1215939329,113.3096030895)) AS distance')
->whereRaw('earth_box(ll_to_earth(23.1215939329,113.3096030895),1000) @> ll_to_earth(team.lat, team.lng)')
->paginate(10);
foreach($items as $item) {
echo $item->distance;
}
As you can see minimal effort is needed here to separate raw query to selectRaw()
and whereRaw()
methods.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…