Answers for "pagination on raw query in laravel"

SQL
2

laravel paginate raw sql

$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;
}
Posted by: Guest on May-29-2020
0

laravel pagination having raw query not working

// This works as expected       

		$curPage = IlluminatePaginationPaginator::resolveCurrentPage();
        $total = $model->get()->count();
        $items = $model->forPage($curPage, $showPerPag)->get();
        $paginated = new IlluminatePaginationLengthAwarePaginator($items, $total, $showPerPage, $curPage, ['path' => request()->url(), 'query' => request()->query()]);
Posted by: Guest on November-12-2020

Code answers related to "SQL"

Browse Popular Code Answers by Language