/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($specialty = '', $location = '') { // Prepare query search result set $this->data['options'] = new DataLoader(); $this->data['location'] = $this->data['options']->getIdValue($location, 'location_cities'); $this->data['specialty'] = $this->data['options']->getIdValue($specialty, 'specializations'); // Prepare additional query $location_query = $location ? array($this->data['location']->id) : array(); if (isset($_GET['locations'])) { if ($_GET['locations']) { $location_query = array_merge($location_query, explode('-', $_GET['locations'])); } } $specialty_query = $specialty ? array($this->data['specialty']->id) : array(); if (isset($_GET['specialty'])) { if ($_GET['specialty']) { $specialty_query = array_merge($specialty_query, explode('-', $_GET['specialty'])); } } $this->data['query'] = array('specializations' => $specialty_query, 'locations' => $location_query); $this->data['ip'] = $_SERVER['REMOTE_ADDR'] == '127.0.0.1' ? '112.199.47.222' : $_SERVER['REMOTE_ADDR']; $this->data['ip_loc'] = json_decode(file_get_contents('http://ipinfo.io/' . $this->data['ip'] . '/json')); $ch = curl_init('http://ipinfo.io/' . $this->data['ip'] . '/json'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $this->data['ip_loc'] = json_decode(curl_exec($ch)); $this->data['coordiantes'] = explode(",", $this->data['ip_loc']->loc); $this->data['doctors_list'] = $this->data['options']->buildDoctorsList($this->data['coordiantes'][0], $this->data['coordiantes'][1], isset($_GET['page']) ? $_GET['page'] < 2 ? 0 : ($_GET['page'] == 2 ? 25 : ($_GET['page'] - 1) * 25) : 0, 25, $this->data['query']); $this->data['doctors'] = json_decode($this->data['doctors_list']); $this->doctor = new Doctors(); $this->data['list_count'] = $this->doctor->getDoctorsListCount($this->data['coordiantes'][0], $this->data['coordiantes'][1], $this->data['query']); $this->data['paginator'] = new LengthAwarePaginator($this->data['doctors_list'], count($this->data['list_count']), 25, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]); // Prepare page title if ($specialty && $location) { $this->data['title'] = config('constants.general_title') . ' - Doctors of ' . $this->data['specialty']->specialization . ' in ' . $this->data['location']->city_name; } else { $this->data['title'] = config('constants.general_title') . ' - Doctors in the Philippines listed'; } // Load data for both specialties and locations dropdown search $this->data['specialties'] = DB::table('specializations')->get(); $this->data['locations'] = json_decode($this->data['options']->getLocations('provinces')); // Load data for sidebar options of locations and specialties $this->data['opt_specs'] = DB::table('specializations')->take(10)->get(); $this->data['opt_locs'] = $this->data['options']->getOptionsLocations($location ? $this->data['location']->province_id : 0); if ($location && $specialty) { return view('doctors.index')->with($this->data); } else { } }