1$items = DB::table('team')
2 ->selectRaw('SELECT *,earth_distance(ll_to_earth(team.lat, team.lng), ll_to_earth(23.1215939329,113.3096030895)) AS distance')
3 ->whereRaw('earth_box(ll_to_earth(23.1215939329,113.3096030895),1000) @> ll_to_earth(team.lat, team.lng)')
4 ->paginate(10);
5
6foreach($items as $item) {
7 echo $item->distance;
8}
1 $curPage = \Illuminate\Pagination\Paginator::resolveCurrentPage();
2 $total = $model->get()->count();
3 $items = $model->forPage($curPage, $showPerPag)->get();
4 $paginated = new \Illuminate\Pagination\LengthAwarePaginator($items, $total, $showPerPage, $curPage, ['path' => request()->url(), 'query' => request()->query()]);
5
1// This works as expected
2
3 $curPage = \Illuminate\Pagination\Paginator::resolveCurrentPage();
4 $total = $model->get()->count();
5 $items = $model->forPage($curPage, $showPerPag)->get();
6 $paginated = new \Illuminate\Pagination\LengthAwarePaginator($items, $total, $showPerPage, $curPage, ['path' => request()->url(), 'query' => request()->query()]);
7