diff --git a/app/Database/migrations/2021_11_27_132418_add_hub_to_aircraft.php b/app/Database/migrations/2021_11_27_132418_add_hub_to_aircraft.php new file mode 100644 index 00000000..a4157717 --- /dev/null +++ b/app/Database/migrations/2021_11_27_132418_add_hub_to_aircraft.php @@ -0,0 +1,15 @@ +string('hub_id', 5)->nullable()->after('airport_id'); + }); + } +} diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index 1a62d134..842d7bb3 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -79,6 +79,7 @@ class AircraftController extends Controller { return view('admin.aircraft.create', [ 'airports' => $this->airportRepo->selectBoxList(), + 'hubs' => $this->airportRepo->selectBoxList(true, true), 'subfleets' => Subfleet::all()->pluck('name', 'id'), 'statuses' => AircraftStatus::select(false), 'subfleet_id' => $request->query('subfleet'), @@ -143,6 +144,7 @@ class AircraftController extends Controller return view('admin.aircraft.edit', [ 'aircraft' => $aircraft, 'airports' => $this->airportRepo->selectBoxList(), + 'hubs' => $this->airportRepo->selectBoxList(true, true), 'subfleets' => Subfleet::all()->pluck('name', 'id'), 'statuses' => AircraftStatus::select(false), ]); diff --git a/app/Models/Aircraft.php b/app/Models/Aircraft.php index 4bf59924..3b39f75f 100644 --- a/app/Models/Aircraft.php +++ b/app/Models/Aircraft.php @@ -13,6 +13,7 @@ use Znck\Eloquent\Traits\BelongsToThrough; * @property int id * @property mixed subfleet_id * @property string airport_id The apt where the aircraft is + * @property string hub_id The apt where the aircraft is based * @property string ident * @property string name * @property string icao @@ -22,6 +23,7 @@ use Znck\Eloquent\Traits\BelongsToThrough; * @property float zfw * @property string hex_code * @property Airport airport + * @property Airport hub * @property Subfleet subfleet * @property int status * @property int state @@ -39,6 +41,7 @@ class Aircraft extends Model protected $fillable = [ 'subfleet_id', 'airport_id', + 'hub_id', 'iata', 'icao', 'name', @@ -127,6 +130,11 @@ class Aircraft extends Model return $this->belongsTo(Airport::class, 'airport_id'); } + public function hub() + { + return $this->hasOne(Airport::class, 'id', 'hub_id'); + } + public function pireps() { return $this->hasMany(Pirep::class, 'aircraft_id'); diff --git a/app/Services/ImportExport/AircraftImporter.php b/app/Services/ImportExport/AircraftImporter.php index 01dbd7b3..be6e0837 100644 --- a/app/Services/ImportExport/AircraftImporter.php +++ b/app/Services/ImportExport/AircraftImporter.php @@ -25,6 +25,7 @@ class AircraftImporter extends ImportExport 'subfleet' => 'required', 'iata' => 'nullable', 'icao' => 'nullable', + 'hub_id' => 'nullable', 'airport_id' => 'nullable', 'name' => 'required', 'registration' => 'required', @@ -53,7 +54,7 @@ class AircraftImporter extends ImportExport } /** - * Import a flight, parse out the different rows + * Import an aircraft, parse out the different rows * * @param array $row * @param int $index diff --git a/resources/views/admin/aircraft/fields.blade.php b/resources/views/admin/aircraft/fields.blade.php index 20e4b1c8..27c1742c 100644 --- a/resources/views/admin/aircraft/fields.blade.php +++ b/resources/views/admin/aircraft/fields.blade.php @@ -5,7 +5,7 @@ Subfleet and Status
{{ $errors->first('subfleet_id') }}
{{ $errors->first('subfleet_id') }}
{{ $errors->first('hub_id') }}
+{{ $errors->first('airport_id') }}