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

前端 未结 7 1884
不知归路
不知归路 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:23

    Using Eloquent, I know you can pass columns to the paginator, something like this:

    Post::having('distance','<=', $distance)
       ->paginate(10, array('*', DB::raw($haversineSQL . ' as distance')));
    

    Not sure if it works without Eloquent, but you could give it a try.

提交回复
热议问题