| It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ Route::get('/', function () { return View::make('homepage', ['title' => 'Home']); }); Route::get('/location/', function () { if (Input::has('lat') && Input::has('lon')) { return Redirect::to('/location/' . Input::get('lat') . '/' . Input::get('lon')); } else { return Redirect::to('/')->withMessage('An error occurred.'); } }); Route::get('/location/{lat}/{lon}', array('as' => 'location', function ($lat, $lon) { $stops = Stop::select(DB::raw('*, ST_AsText(location) AS location'))->where('inuse', '=', true)->whereRaw('ST_DWithin(location, ST_GeographyFromText(\'SRID=4326;POINT(' . floatval($lon) . ' ' . floatval($lat) . ')\'), 1000)')->orderByRaw('ST_Distance(location, ST_GeographyFromText(\'SRID=4326;POINT(' . floatval($lon) . ' ' . floatval($lat) . ')\'))')->limit(10)->get(); if (!$stops->isEmpty()) { $colours = array("black", "brown", "green", "purple", "yellow", "blue", "gray", "orange", "red", "white"); $letter = "A"; foreach ($stops as &$stop) { $stop['colour'] = current($colours); $stop['letter'] = $letter; $letter++; next($colours); $coords = explode(' ', $stop['location']); $stop['lon'] = filter_var($coords[0], FILTER_SANITIZE_NUMBER_FLOAT, ['flags' => FILTER_FLAG_ALLOW_FRACTION]); $stop['lat'] = filter_var($coords[1], FILTER_SANITIZE_NUMBER_FLOAT, ['flags' => FILTER_FLAG_ALLOW_FRACTION]); } return View::make('stoplist')->withStops($stops)->withTitle('Stops'); } else { return Redirect::to('/')->withMessage('We couldn\'t find any stops within 3km of your location.');
public function produceTimetable($stop, $forceLive = NULL) { // Check for stop existence $stopData = Stop::select(DB::raw('*, ST_AsText(location) AS location'))->where('id', '=', $stop)->get(); $plannedData = FALSE; if ($stopData->isEmpty()) { return View::make('timetable')->withTitle('Timetable')->withError('Invalid stop entered'); } else { $stopData = Stop::select(DB::raw('*, ST_AsText(location) AS location'))->where('id', '=', $stop)->get(); $coords = explode(' ', $stopData[0]['location']); $stopData[0]['lon'] = filter_var($coords[0], FILTER_SANITIZE_NUMBER_FLOAT, ['flags' => FILTER_FLAG_ALLOW_FRACTION]); $stopData[0]['lat'] = filter_var($coords[1], FILTER_SANITIZE_NUMBER_FLOAT, ['flags' => FILTER_FLAG_ALLOW_FRACTION]); } if (Redis::exists($stop)) { $timedata = json_decode(Redis::get($stop), TRUE); $creditMessage = 'Retrieved from cache. Public sector information from Traveline licensed under the Open Government Licence v2.0.'; } else { if (Session::has('foreign')) { return Redirect::to('/regionblock'); } else { // Determine the data provider to use if (isset($forceLive)) { $timedata = TimetableController::getNationalData($stop); $creditMessage = 'Retrieved from live data per user request. Public sector information from Traveline licensed under the Open Government Licence v2.0.'; } else { if (substr($stop, 0, 3) === '180') { $timedata = TimetableController::getManchesterData($stop); $creditMessage = 'Retrieved from planned timetables and may not take into account sudden service changes. Public sector information from Transport for Greater Manchester. Contains Ordnance Survey data © Crown copyright and database rights 2014'; $plannedData = TRUE; } else { if (substr($stop, 0, 3) === '490') { $timedata = TimetableController::getLondonData($stop); $creditMessage = 'Retrieved from live data. Data provided by Transport for London'; } else { $timedata = TimetableController::getNationalData($stop); $creditMessage = 'Retrieved from live data. Public sector information from Traveline licensed under the Open Government Licence v2.0.'; } } } } } // Extract the location info if ($timedata === FALSE) { return View::make('timetable')->withTitle('Timetable')->withScheduled($plannedData)->withStop($stopData)->withError('No services found at this stop.'); } else { return View::make('timetable')->withTimetable($timedata)->withScheduled($plannedData)->withStop($stopData)->withTitle('Timetable')->withCredit($creditMessage); } }