Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何用haversine公式对有说服力的查询进行分页_Php_Laravel_Pagination_Eloquent_Laravel Pagination - Fatal编程技术网

Php 如何用haversine公式对有说服力的查询进行分页

Php 如何用haversine公式对有说服力的查询进行分页,php,laravel,pagination,eloquent,laravel-pagination,Php,Laravel,Pagination,Eloquent,Laravel Pagination,我正在按距离和搜索词进行搜索查询,但在Elountent中使用“Having”时,标准分页不再有效 这是我的密码: $haversine = '( 3959 * acos( cos( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin( radians(?) ) * sin( radians( latitude ) ) ) )'; $stores =

我正在按距离和搜索词进行搜索查询,但在Elountent中使用“Having”时,标准分页不再有效

这是我的密码:

    $haversine = '( 3959 * acos( cos( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin( radians(?) ) * sin( radians( latitude ) ) ) )';
    $stores = Store::select(
        DB::raw("*, $haversine AS distance"))
        ->having("distance", "<", $input['distance'])
        ->orderBy("distance")
        ->setBindings(array(
            $latitude,
            $longitude,
            $latitude
        ))
        ->with(array(
            'offers' => function($query) {
                if(Input::has('term')) {
                    $query->whereHas('product', function ($product_query) {
                        $product_query->where(function($term_query) {
                            $fields = array('name', 'description','model_number');
                            foreach($fields as $field) {
                                $term_query->orWhere($field, 'LIKE', '%' . Input::get('term') . '%');
                            }
                            $term_query->orWhereHas('brand', function($brand_query) {
                                $brand_query->where('name', 'LIKE', '%' . Input::get('term') . '%');
                            });
                        });
                    });
                }
                $query->orderBy('price', 'ASC');
            })
        )
        ->get();

在雄辩中使用having子句进行分页时,我也遇到了同样的问题

这对我很有用:

不要在'having'子句中使用列的别名,而是使用实际计算

而不是:

$model->select(DB::raw("*, $haversine AS distance"))->having("distance", "<", $input['distance']);

$model->select(DB::raw(“*,$haversine作为距离”)->having(“距离”,“您引用了一些有助于解决问题的链接。您尝试的实现此处所述解决方案的代码在哪里?查看这些代码,以确定您是否遗漏了一些内容,这将有助于确定您是否遗漏了一些内容。嗨,Bogdan,我已用尝试的代码更新了问题。”
$model->select(DB::raw("*, $haversine AS distance"))->having("distance", "<", $input['distance']);
$model->select("*")->having(DB:raw($haversine), "<", $input['distance']);