public function index() { if (Input::get('coordinates')) { $cd = Input::get('coordinates'); $_cd = explode(',', $cd); $wd = $_cd[0]; $jd = $_cd[1]; $schools = School::all(); $ret = array(); $radius = Input::get('radius') ? Input::get('radius') : 30000; foreach ($schools as $v) { $tmp = explode(',', $v->coordinates); $lat1 = $tmp[0]; $lng1 = $tmp[1]; $dst = $this->getDistance($lat1, $lng1, $wd, $jd); if ($dst < $radius) { $ret[floor($dst)] = $v; } ksort($ret); $out = []; foreach ($ret as $v) { $out[] = $v; } } return $this->output(array('schoolList' => $out)); } else { return $this->output(array('schoolList' => School::orderBy('ord', 'desc')->limit(4)->get())); } }
/** * Show the peace school screen to the user. * * @return Response */ public function school($location = null) { //Decide whether details or school list page to open if ($location == null) { $school = School::orderBy('id')->get(); return view('publicViewables.school')->with('schools', $school); } //Convert slugged text to normal spaced text if (str_contains($location, '-')) { $location = str_replace('-', ' ', $location); } $school = School::where('location', '=', $location)->first() or abort('404'); return view('publicViewables.viewSchool')->with('school', $school); }