title: Can i get my variable out the foreach loop ? and send it with response along with the all users Data
body: <ol>
  <li><p><strong>Is it possible that I get both user details and distance along with users details</strong></p>
  </li>
  <li><p><strong>I want all the users details which I get in $data variable along with the $distance</strong></p>
  </li>
  <li><p><strong>both variables should be on the response.</strong></p>
  <pre><code> public function getProfessionalByCityLatLon(Request $request)
       {
        $data = DB::table('profiles')
         -&gt;leftJoin('cities','profiles.city','=','cities.id')
         -&gt;leftJoin('users', 'profiles.user_id', '=', 'users.id')
         -&gt;where('cities.name', '=', $request-&gt;select_city)                        
         -&gt;get();
  
           foreach($data as $data1){
               $longitude1 = 23.6676092; // i will get it later from $request 
               $latitude1 = 86.0490814; // Same with this also
               $longitude2 = $data1-&gt;longitude;
               $latitude2 = $data1-&gt;latitude;
  
               $unit = 'kilometers';
               $theta = $longitude1 - $longitude2; 
               $distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta))); 
               $distance = acos($distance); 
               $distance = rad2deg($distance); 
               $distance = $distance * 60 * 1.1515; 
               switch($unit) { 
                   case 'miles': 
                   break; 
                   case 'kilometers' : 
                   $distance = $distance * 1.609344;
                   $distance = $distance * 1000;  
  
               } 
               $profDistance = (round($distance, 2));
  
           }
           $response = [
               'success' =&gt; true,
               'distance' =&gt; $profDistance,
               'user' =&gt; $data,
               'message' =&gt; 'City retrieved successfully.',
           ];
  
           Log::info($response);
           return response()-&gt;json($response, 200);
       }
  </code></pre>
  </li>
  </ol>