我必须解决问题,我需要搜索用户是否在特定半径范围内。我在用户上有两个连接表,地址和搜索半径...查询将收到两个参数lat和log。
$query = Users::query();
$query->with('location', 'serach_area');
$query->whereHas('location', function ($query) use ($latitude, $longitude) {
$query->select('users_locations.latitude as latitude', 'users_locations.longitude as longitude', 'users_locations.user_id', 'search_area.radius s radius')
->selectRaw("(6371 * acos(cos(radians('.$latitude.')) * cos(radians(latitude)) * cos(radians(longitude) - radians('.$longitude.')) sin(radians('.$latitude.')) * sin(radians(latitude)))) as haversine")
->having("haversine", "<", "radius"); });
如果我用硬编码的号码,我将无法获得搜索区域。半径,如果有人有任何想法请发表评论,这将非常有效