public function jsonadd(Request $request) { $data = json_decode($request->getContent(), true); foreach ($data as $d) { $apt = new AirportsAPI(); $depicao = Airport::where('icao', $d['depicao'])->get(); $arricao = Airport::where('icao', $d['arricao'])->get(); if ($depicao->isEmpty()) { $apt->addFromDB($d['depicao']); } if ($arricao->isEmpty()) { $apt->addFromDB($d['arricao']); } $entry = new Schedule(); $entry->code = $d['code']; $entry->flightnum = $d['flightnum']; $entry->depicao = $d['depicao']; $entry->arricao = $d['arricao']; $entry->route = $d['route']; $entry->aircraft = $d['aircraft']; $entry->type = $d['type']; $entry->daysofweek = $d['daysofweek']; $entry->enabled = $d['enabled']; $entry->save(); } }
public function addFromDB($icao) { // lets request the airport identifier from the central database $client = new Client(); $res = $client->request('GET', 'http://fsvaos.net/api/central/airports', ['query' => ['icao' => $icao]])->getBody(); // Add the airport to the database $data = json_decode($res, true); $airport = new Airport(); //return dd($data); try { $airport->id = $data[0]['id']; $airport->name = $data[0]['name']; $airport->city = $data[0]['municipality']; $airport->iata = $data[0]['iata_code']; $airport->icao = $data[0]['ident']; $airport->lat = $data[0]['latitude_deg']; $airport->lon = $data[0]['longitude_deg']; $airport->country = $data[0]['iso_country']; } catch (Exception $e) { return dd($data); } $airport->save(); }
public function controls($type = NULL, $model = NULL) { return ['from' => \Easy\Form\Textbox::make('~layouts.form.controls.textboxes.textbox')->name('from')->caption('From')->placeholder('Give please accurate address including post code')->class('form-control data-source')->controlsource('from')->controltype('textbox')->out(), 'from_nr' => \Easy\Form\Textbox::make('~layouts.form.controls.textboxes.textbox')->name('from_nr')->caption('Pick up')->ng_model('form.from_nr')->placeholder('postcode: (NR1 to NR7 only), house number,street')->class('form-control data-source')->controlsource('from_nr')->controltype('textbox')->value($model != NULL ? $model->name : '')->out(), 'to' => \Easy\Form\Textbox::make('~layouts.form.controls.textboxes.textbox')->name('to')->caption('To')->placeholder('Give please accurate address including post code')->class('form-control data-source')->controlsource('to')->controltype('textbox')->out(), 'to_nr' => \Easy\Form\Textbox::make('~layouts.form.controls.textboxes.textbox')->name('to_nr')->caption('To')->ng_model('form.to_nr')->placeholder('postcode: (NR1 to NR7 only), house number,street')->class('form-control data-source')->controlsource('to_nr')->controltype('textbox')->value($model != NULL ? $model->name : '')->out(), 'locality' => \Easy\Form\Textbox::make('~layouts.form.controls.textboxes.textbox')->name('locality')->caption('City')->class('form-control data-source')->controlsource('locality')->controltype('textbox')->out(), 'country' => \Easy\Form\Textbox::make('~layouts.form.controls.textboxes.textbox')->name('country')->caption('Country')->class('form-control data-source')->controlsource('country')->controltype('textbox')->out(), 'postal_code' => \Easy\Form\Textbox::make('~layouts.form.controls.textboxes.textbox-addon')->name('postal_code')->caption('Postal code')->class('form-control data-source')->readonly(0)->controlsource('postal_code')->controltype('textbox')->addon(['before' => '<i class="fa fa-envelope"></i>', 'after' => NULL])->out(), 'options' => \Easy\Form\Combobox::make('~layouts.form.controls.comboboxes.combobox')->name('option')->caption('Pick-up Point:')->class('form-control data-source input-group form-select selectpicker init-on-update-delete')->controlsource('option')->controltype('combobox')->enabled('false')->options(['' => '- Select -'] + Options::toCombobox())->out(), 'airport' => \Easy\Form\Combobox::make('~layouts.form.controls.comboboxes.combobox')->name('airport')->caption('Airport:')->class('form-control data-source input-group form-select selectpicker init-on-update-delete')->controlsource('airport')->controltype('combobox')->enabled('false')->options(Airport::toCombobox())->out()]; }
/** * Gets an airport by code * * @param string $code The airport code * @return Illuminate\Database\Query\Buildert */ public function getByCode($code) { return \App\Models\Airport::where('code', '=', $code); }
public function actionSearch($airport_code = '') { return Airport::find()->where(['airport_code' => $airport_code])->all(); }