From d90f338321ac7308ab1ae92d07264d673722ea6d Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 18 Apr 2026 16:45:13 +1000 Subject: [PATCH] Add more airlines and fix edit bugs --- app/Http/Controllers/FlightController.php | 23 ++++++------ .../Controllers/FlightImportController.php | 8 ++--- app/Http/Controllers/SearchController.php | 6 ++-- app/Models/Aircraft.php | 13 +++++-- app/Models/Airline.php | 14 ++++++-- app/Models/Airport.php | 22 ++++++++++-- app/Models/SeatType.php | 3 ++ .../2026_04_18_023946_add_more_airlines.php | 3 ++ ...2026_04_18_050632_add_horizontal_falls.php | 36 +++++++++++++++++++ .../Components/FlightsGoneBy/BoardingPass.vue | 6 ++-- .../FlightsGoneBy/DepartureBoard.vue | 2 +- resources/js/Types/types.d.ts | 3 ++ 12 files changed, 111 insertions(+), 28 deletions(-) create mode 100644 database/migrations/2026_04_18_050632_add_horizontal_falls.php diff --git a/app/Http/Controllers/FlightController.php b/app/Http/Controllers/FlightController.php index 7698a36..6aeee7d 100644 --- a/app/Http/Controllers/FlightController.php +++ b/app/Http/Controllers/FlightController.php @@ -42,17 +42,18 @@ class FlightController extends Controller // Extract the airline code prefix — letters at the start e.g. "QF" from "QF1" preg_match('/^([A-Z]{2,3})/', $number, $matches); - $iataCode = $matches[1] ?? null; + $code = $matches[1] ?? null; + $isIata = strlen($code) === 2; + $codeColumn = $isIata ? 'IATA_code' : 'ICAO_code'; - $airlines = $iataCode - ? Airline::where('IATA_code', $iataCode) + $airlines = $code + ? Airline::where($codeColumn, $code) ->get() - ->map(fn ($a) => ['value' => $a->id, 'title' => $a->name]) - : collect(); - + ->map(fn ($airline) => ['value' => $airline->id, 'title' => $airline->display_name]) + : collect()->toArray(); return response()->json([ 'airline_options' => $airlines, - 'from_options' => [], // populate from a flight schedule API if you have one + 'from_options' => [], 'to_options' => [], 'aircraft_options' => [], ]); @@ -137,12 +138,12 @@ class FlightController extends Controller 'flight_class' => $flight->flightClass->toArray(), 'flight_reason' => $flight->flightReason->toArray(), 'airline_options' => $flight->airline - ? [['value' => $flight->airline->id, 'title' => $flight->airline->displayName()]] + ? [['value' => $flight->airline->id, 'title' => $flight->airline->display_name]] : [], - 'from_options' => [['value' => $flight->departureAirport->id, 'title' => $flight->departureAirport->displayName(), 'country_code' => strtolower($flight->departureAirport->region->country->code)]], - 'to_options' => [['value' => $flight->arrivalAirport->id, 'title' => $flight->arrivalAirport->displayName(), 'country_code' => strtolower($flight->arrivalAirport->region->country->code)]], + 'from_options' => [['value' => $flight->departureAirport->id, 'title' => $flight->departureAirport->display_name, 'country_code' => strtolower($flight->departureAirport->region->country->code)]], + 'to_options' => [['value' => $flight->arrivalAirport->id, 'title' => $flight->arrivalAirport->display_name, 'country_code' => strtolower($flight->arrivalAirport->region->country->code)]], 'aircraft_options' => $flight->aircraft - ? [['value' => $flight->aircraft->id, 'title' => $flight->aircraft->displayName()]] + ? [['value' => $flight->aircraft->id, 'title' => $flight->aircraft->display_name]] : [], ]; return Inertia::render('AddFlight', [ diff --git a/app/Http/Controllers/FlightImportController.php b/app/Http/Controllers/FlightImportController.php index 3f2ad5e..788e45f 100644 --- a/app/Http/Controllers/FlightImportController.php +++ b/app/Http/Controllers/FlightImportController.php @@ -57,7 +57,7 @@ class FlightImportController extends Controller ->get(['id', 'manufacturer_code', 'model_full_name', 'designator']) ->map(fn($aircraft) => [ 'value' => $aircraft->id, - 'title' => $aircraft->displayName(), + 'title' => $aircraft->display_name, ]) ->values() ->toArray(); @@ -92,9 +92,9 @@ class FlightImportController extends Controller ->limit(10) ->orderBy('id') ->get(['id', 'name', 'municipality', 'iata_code', 'icao_code', 'region_id']) - ->map(fn($airport) => [ + ->map(fn(Airport $airport) => [ 'value' => $airport->id, - 'title' => $airport->displayName(), + 'title' => $airport->display_name, 'country_code' => strtolower($airport?->region->country->code ?? ''), ]) ->values() @@ -131,7 +131,7 @@ class FlightImportController extends Controller ->get(['id', 'name', 'IATA_code', 'ICAO_code']) ->map(fn($airline) => [ 'value' => $airline->id, - 'title' => $airline->displayName(), + 'title' => $airline->display_name, ]) ->values() ->toArray(); diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 326626d..0b7cf92 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -29,7 +29,7 @@ class SearchController extends Controller ->get(['id', 'name', 'IATA_code', 'ICAO_code', 'logo']) ->map(fn($airline) => [ 'value' => $airline->id, - 'title' => $airline->displayName(), + 'title' => $airline->display_name, ]) ->values(); } @@ -47,7 +47,7 @@ class SearchController extends Controller ->get(['id', 'manufacturer_code', 'model_full_name', 'designator']) ->map(fn($aircraft) => [ 'value' => $aircraft->id, - 'title' => $aircraft->displayName(), + 'title' => $aircraft->display_name, ]) ->values(); } @@ -76,7 +76,7 @@ class SearchController extends Controller ->get(['id', 'name', 'municipality', 'iata_code', 'icao_code', 'region_id']) ->map(fn($airport) => [ 'value' => $airport->id, - 'title' => $airport->displayName(), + 'title' => $airport->display_name, 'country_code' => strtolower($airport->region->country->code), ]) ->values(); diff --git a/app/Models/Aircraft.php b/app/Models/Aircraft.php index 971ee22..f826765 100644 --- a/app/Models/Aircraft.php +++ b/app/Models/Aircraft.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; class Aircraft extends Model @@ -20,7 +21,15 @@ class Aircraft extends Model 'engine_count' => 'integer', ]; - public function displayName() : string{ - return "{$this->manufacturer_code} {$this->model_full_name} ({$this->designator})"; + protected $appends = [ + 'display_name', + ]; + + protected function displayName() : Attribute{ + return Attribute::make( + get: function () { + return "{$this->manufacturer_code} {$this->model_full_name} ({$this->designator})"; + } + ); } } diff --git a/app/Models/Airline.php b/app/Models/Airline.php index 2a92b5b..122c061 100644 --- a/app/Models/Airline.php +++ b/app/Models/Airline.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -26,9 +27,18 @@ class Airline extends Model public $timestamps = false; + protected $appends = [ + 'display_name', + ]; - public function displayName() : string { - return "{$this->name} ({$this->IATA_code}/{$this->ICAO_code})"; + protected function displayName() : Attribute{ + return Attribute::make( + get: function () { + $codes = array_filter([$this->IATA_code, $this->ICAO_code]); + $codeString = count($codes) ? ' (' . implode('/', $codes) . ')' : ''; + return "{$this->name}{$codeString}"; + } + ); } public function country(): BelongsTo diff --git a/app/Models/Airport.php b/app/Models/Airport.php index e219ce8..faf43b8 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -27,8 +28,25 @@ class Airport extends Model 'elevation_ft' => 'integer', ]; - public function displayName() : string{ - return "{$this->municipality} / {$this->name} ({$this->iata_code}/{$this->icao_code})"; + protected $appends = [ + 'display_code', + 'display_name', + ]; + + protected function displayName() : Attribute{ + return Attribute::make( + get: function () { + $codes = array_filter([$this->iata_code, $this->icao_code]); + $codeString = count($codes) ? ' (' . implode('/', $codes) . ')' : ''; + return "{$this->municipality} / {$this->name}{$codeString}"; + } + ); + } + protected function displayCode(): Attribute + { + return Attribute::make( + get: fn () => $this->iata_code ?? $this->icao_code ?? $this->local_code ?? '---' + ); } public function region(): BelongsTo diff --git a/app/Models/SeatType.php b/app/Models/SeatType.php index 8d068b8..f79cd27 100644 --- a/app/Models/SeatType.php +++ b/app/Models/SeatType.php @@ -6,5 +6,8 @@ use Illuminate\Database\Eloquent\Model; class SeatType extends Model { + protected $fillable = [ + 'name', + ]; public $timestamps = false; } diff --git a/database/migrations/2026_04_18_023946_add_more_airlines.php b/database/migrations/2026_04_18_023946_add_more_airlines.php index ab617a7..eb7fa4c 100644 --- a/database/migrations/2026_04_18_023946_add_more_airlines.php +++ b/database/migrations/2026_04_18_023946_add_more_airlines.php @@ -2,6 +2,7 @@ use App\Models\Airline; use App\Models\Country; +use App\Models\SeatType; use App\Models\UserFlight; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; @@ -77,6 +78,8 @@ return new class extends Migration UserFlight::where('flight_reason_id', null)->update(['flight_reason_id' => 0]); UserFlight::where('flight_class_id', null)->update(['flight_class_id' => 0]); + UserFlight::where('flight_reason_id', 0)->update(['flight_reason_id' => 1]); + SeatType::where('id', 0)->update(['name' => 'Unassigned']); } /** diff --git a/database/migrations/2026_04_18_050632_add_horizontal_falls.php b/database/migrations/2026_04_18_050632_add_horizontal_falls.php new file mode 100644 index 0000000..8043127 --- /dev/null +++ b/database/migrations/2026_04_18_050632_add_horizontal_falls.php @@ -0,0 +1,36 @@ + 'Horizontal Falls Pontoon', + 'region_id' => Region::whereCode('AU-WA')->first()->id, + 'municipality' => 'Horizontal Falls', + 'latitude_deg' => -16.373295, + 'longitude_deg' => 123.964757, + 'elevation_ft' => 0, + 'type' => 'seaplane_base', + 'timezone' => 'Australia/Perth', + ]); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; diff --git a/resources/js/Components/FlightsGoneBy/BoardingPass.vue b/resources/js/Components/FlightsGoneBy/BoardingPass.vue index 025da9f..6974d34 100644 --- a/resources/js/Components/FlightsGoneBy/BoardingPass.vue +++ b/resources/js/Components/FlightsGoneBy/BoardingPass.vue @@ -30,7 +30,7 @@ function classKey(flight: Flight): string {
-
{{ flight.departure_airport.iata_code }}
+
{{ flight.departure_airport.display_code}}
{{ flight.departure_airport.municipality }}
{{ flight.departure_date_display }}
@@ -50,7 +50,7 @@ function classKey(flight: Flight): string {
-
{{ flight.arrival_airport.iata_code }}
+
{{ flight.arrival_airport.display_code}}
{{ flight.arrival_airport.municipality }}
{{ flight.arrival_date_display ?? flight.departure_date_display }}
@@ -213,6 +213,7 @@ function classKey(flight: Flight): string { font-size: 0.8rem; color: #778899; font-weight: 500; + white-space: nowrap; } .pass-endpoint-date { @@ -258,7 +259,6 @@ function classKey(flight: Flight): string { font-size: 0.72rem; color: #778899; text-align: center; - white-space: nowrap; } .pass-aircraft { diff --git a/resources/js/Components/FlightsGoneBy/DepartureBoard.vue b/resources/js/Components/FlightsGoneBy/DepartureBoard.vue index 35dc89a..34866ed 100644 --- a/resources/js/Components/FlightsGoneBy/DepartureBoard.vue +++ b/resources/js/Components/FlightsGoneBy/DepartureBoard.vue @@ -204,7 +204,7 @@ const tableItems = computed(() => {{(item as Flight).seat_number}} - {{(item as Flight).seat_type?.name}} + {{(item as Flight).seat_type?.name}} diff --git a/resources/js/Types/types.d.ts b/resources/js/Types/types.d.ts index b3456b2..b3b5cce 100644 --- a/resources/js/Types/types.d.ts +++ b/resources/js/Types/types.d.ts @@ -52,6 +52,7 @@ export interface Airport { created_at: string | null updated_at: string | null timezone: string + display_code: string } export type Continent = { @@ -81,6 +82,7 @@ export interface Airline { logo: string | null country_id: number country?: Country + display_name: string } @@ -96,6 +98,7 @@ export interface Aircraft { wtc: string created_at: string | null updated_at: string | null + display_name: string } export interface SeatType {