已解决 使用whereHas即可
分类店铺两个模型定义了多对多。
现在需要对某一个分类下的所有店铺按距离进行排序,数据库存储的是经纬度。
//获取分类下的店铺
$shop_categories = ShopCategory::where('title',$cat)->first();
$shops = $shop_categories->shops;
//所有店铺按距离排序的代码
$shops = Shop::select(DB::raw('*, (st_distance (point (lng, lat),point('.$lng.','.$lat.') ) * 111195 / 1000) AS
distance'))->orderBy('distance')->paginate(10);
现在的问题是,如何将者两段代码合并起来,获取某个分类下的店铺,并按距离排序。