Add more airlines and fix edit bugs

This commit is contained in:
2026-04-18 16:45:13 +10:00
parent 63d6fb9e76
commit d90f338321
12 changed files with 111 additions and 28 deletions
+12 -11
View File
@@ -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', [
@@ -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();
+3 -3
View File
@@ -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();
+11 -2
View File
@@ -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})";
}
);
}
}
+12 -2
View File
@@ -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
+20 -2
View File
@@ -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
+3
View File
@@ -6,5 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class SeatType extends Model
{
protected $fillable = [
'name',
];
public $timestamps = false;
}