function store() { $rules = array('icao' => 'alpha_num|required', 'iata' => 'alpha_num', 'name' => 'required', 'city' => 'required', 'lat' => 'required|numeric', 'lon' => 'required|numeric', 'elevation' => 'required|numeric', 'country_id' => 'required|exists:countries,id', 'website' => 'url'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { Messages::error($validator->messages()->all()); return Redirect::back()->withInput(); } if (is_null($airport = Airport::whereIcao(Input::get('icao'))->whereNew(true)->first())) { $airport = new Airport(); $airport->icao = Input::get('icao'); $airport->name = Input::get('name'); $airport->new = true; $airport->save(); } Diff::compare($airport, Input::all(), function ($key, $value, $model) { $change = new AirportChange(); $change->airport_id = $model->id; $change->user_id = Auth::id(); $change->key = $key; $change->value = $value; $change->save(); }, ['name', 'iata', 'city', 'country_id', 'lat', 'lon', 'elevation', 'website']); Messages::success('Thank you for your submission. We will check whether all information is correct and soon this airport might be available.'); return Redirect::back(); }
function citypair($departureId, $arrivalId) { $routes = Flight::select('id', 'route', DB::raw('COUNT(route) AS count'))->whereDepartureId($departureId)->whereArrivalId($arrivalId)->where('route', '!=', '')->whereState(2)->groupBy('route')->orderBy('count', 'desc')->get(); $departure = Airport::whereIcao($departureId)->first(); $arrival = Airport::whereIcao($arrivalId)->first(); $this->autoRender(compact('departure', 'arrival', 'routes', 'airports', 'departureId', 'arrivalId'), 'Routes for ' . $departureId . ' - ' . $arrivalId); }
function citypair($matches) { $departure = strtoupper($matches[1]); $arrival = strtoupper($matches[2]); if (!is_null(Airport::whereIcao($departure)->first()) && !is_null(Airport::whereIcao($arrival)->first())) { return Redirect::route('citypair', array('departure' => $departure, 'arrival' => $arrival)); } return false; }
return App::abort(404); } else { return $atc; } }); Route::bind('pilot', function ($value) { $pilot = Pilot::whereVatsimId($value)->first(); if (is_null($pilot) || $value == 0) { return App::abort(404); } else { return $pilot; } }); Route::bind('airport', function ($value, $route) { $admin = in_array('admin', $route->getAction()); $airport = Airport::whereIcao($value); if (!$admin) { $airport->whereNew(false); } $airport = $airport->first(); if (is_null($airport)) { return App::abort(404, 'airport'); } else { return $airport; } }); Route::bind('airline', function ($value, $route) { $admin = in_array('admin', $route->getAction()); $airline = Airline::whereIcao($value); if (!$admin) { $airline = $airline->whereNew(false);
/** * Gets the country ISO code for the airport queried. If the * airport cannot be found it will return an empty string. * * @param string $icao * @return string */ protected function airportCountry($icao) { // We need to return the country code or // empty if the airport cannot be found in our database $airport = Airport::whereIcao($icao)->first(); return is_null($airport) ? '' : $airport->country_id; }