尝试将此SQL查询转换为Laravel查询
$query = "SELECT *, ( 3959 * acos( cos( radians('$lat') ) *
cos( radians( latitude ) ) *
cos( radians( longitude ) -
radians('$lon') ) +
sin( radians('$lat') ) *
sin( radians( latitude ) ) ) )
AS distance FROM yourtable HAVING distance < '$miles' ORDER BY distance ASC LIMIT 0, 5";
继承人我做了什么,但我想我真的不知道这件事。
$stores = DB::table('stores')
->select( DB::raw( 'stores.*, ( ( 3959 * acos( cos( radians('.$lat.') ) *
cos( radians( stores.latitude ) ) *
cos( radians( stores.longitude ) -
radians('.$lon.') ) +
sin( radians('.$lat.') ) *
sin( radians( stores.latitude ) ) ) )
as distance' ) )
->orderBy('distance')->where('domain',$domain->appEnv)->get();