Yes, you already pass in a value from the .env (which should be in a config file). So all you need to do is allow the users to store the value somewhere and use that but if that is null then fallback.
$radius = $user->radius ?: env('RADIUS', 50)
I currently have a fixed radius of 50km, which is an ENV constant, for finding all users within X radius of a particular set of coordinates. What I would like to achieve is allowing users to set their own radius, up to a maximum of 50km and use this value in the search.
User::selectRaw('*, (6371 * acos (cos ( radians('.$lat.') ) * cos( radians( addressLat ) ) * cos( radians( addressLong ) - radians('.$lng.') ) + sin ( radians('.$lat.') ) * sin( radians( addressLat ) ))) AS distance')->orderBy('distance')->having('distance', '<', $radius)->whereNotNull('phone_number')->where('should_receive_quotes', '!=', '0')->get();
$radius = env('RADIUS',50); is the variable currently.
Is it possible to be able to use the value within the users table radius to check whether that user is within the radius of the given coordinates and their custom radius? If there is no value set in the users radius column then it defaults to 50km.
Please or to participate in this conversation.