How to use paginate() with a having() clause when column does not exist in table

前端 未结 7 1891
不知归路
不知归路 2020-12-01 06:41

I have a tricky case ...

Following database query does not work:

DB::table(\'posts\')
->select(\'posts.*\', DB::raw($haversineSQL . \' as distance         


        
7条回答
  •  感情败类
    2020-12-01 07:24

    There is a better way and also works with links:

            $curPage = \Illuminate\Pagination\Paginator::resolveCurrentPage();
            $total = $model->get()->count();
            $items = $model->forPage($curPage, $showPerPag)->get();
            $paginated = new \Illuminate\Pagination\LengthAwarePaginator($items, $total, $showPerPage, $curPage, ['path' => request()->url(), 'query' => request()->query()]);
    

提交回复
热议问题