public function getSearchType()
 {
     $dataReceived = Input::get("data");
     $data_arr = $dataReceived['data'][0];
     $action = $data_arr['action'];
     $type = $data_arr['type'];
     $gender = $data_arr['gender'];
     $ageFrom = intval($data_arr['ageFrom']);
     $ageTo = intval($data_arr['ageTo']);
     $range = intval($data_arr['range']);
     $lati = doubleval($data_arr['lati']);
     $longi = doubleval($data_arr['longi']);
     $distance = new Compatability();
     $users = $users = DB::table('users')->orderBy($type, 'desc')->get();
     $result = array();
     $i = 0;
     foreach ($users as $user) {
         $newDistance = $distance->haversineGreatCircleDistance($lati, $longi, $user->latitude, $user->longitude);
         if ($newDistance <= $range && $user->age >= $ageFrom && $user->age <= $ageTo && $user->gender == $gender) {
             $geocodeFromLatLong = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=' . trim($user->latitude) . ',' . trim($user->longitude) . '&sensor=false');
             $output = json_decode($geocodeFromLatLong);
             $status = $output->status;
             $location = $status == "OK" ? $output->results[1]->formatted_address : '';
             $geocodeFromLatLong2 = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=' . trim($lati) . ',' . trim($longi) . '&sensor=false');
             $output2 = json_decode($geocodeFromLatLong);
             $status2 = $output->status;
             $location2 = $status == "OK" ? $output->results[1]->formatted_address : '';
             $result[$i] = array('username' => $user->username, 'age' => $user->age, 'firstName' => $user->firstName, 'lastName' => $user->lastName, 'photo' => $user->photo, 'locations' => $location, 'location2' => $location2, 'gender' => $gender, 'ageFrom' => $ageFrom, 'ageTo' => $ageTo, 'range' => $range, 'lati' => $lati, 'longi' => $longi, 'gendr' => $gender, 'distance' => $newDistance);
             $i++;
         }
     }
     // dd($result);
     return json_encode($result);
 }
 public function getIndex($id)
 {
     if (Auth::check()) {
         // First Generating List
         $compat = new Compatability();
         $compat->generateCompatibles($id);
         // Getting List Of Compatibles From Model Class and Passing To View
         $result = $compat->showCompatability($id);
         //dd($result);
         return \View::make('compatability_slider')->with("data", $result);
     } else {
         return redirect(url() . '/login');
     }
 }
 public function postIndex()
 {
     $myGender = Input::get("myGender");
     $gender = Input::get("gender");
     $ageFrom = Input::get("age_from");
     $ageTo = Input::get("age_to");
     $zipCode = Input::get("zipcode");
     $range = Input::get("range");
     $getLocation = new SearchController();
     $val = $getLocation->getLnt($zipCode);
     $lati = $val['lat'];
     $longi = $val['lng'];
     $distance = new Compatability();
     $users = $users = DB::table('users')->get();
     $result = array();
     $i = 0;
     foreach ($users as $user) {
         $newDistance = $distance->haversineGreatCircleDistance($lati, $longi, $user->latitude, $user->longitude);
         if ($newDistance <= $range && $user->age >= $ageFrom && $user->age <= $ageTo && $user->gender == $gender) {
             $geocodeFromLatLong = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=' . trim($user->latitude) . ',' . trim($user->longitude) . '&sensor=false');
             $output = json_decode($geocodeFromLatLong);
             $status = $output->status;
             $location = $status == "OK" ? $output->results[1]->formatted_address : '';
             $geocodeFromLatLong2 = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=' . trim($lati) . ',' . trim($longi) . '&sensor=false');
             $output2 = json_decode($geocodeFromLatLong);
             $status2 = $output->status;
             $location2 = $status == "OK" ? $output->results[1]->formatted_address : '';
             $result[$i] = array('username' => $user->username, 'age' => $user->age, 'firstName' => $user->firstName, 'lastName' => $user->lastName, 'photo' => $user->photo, 'location' => $location, 'location2' => $location2, 'gender' => $gender, 'ageFrom' => $ageFrom, 'ageTo' => $ageTo, 'range' => $range, 'lati' => $lati, 'longi' => $longi, 'gendr' => $gender);
             $i++;
         }
     }
     //dd($result);
     return View::make('search')->withusers($result);
     // dd($_POST);
     //return 'search';
 }