Add more airlines and fix edit bugs
This commit is contained in:
@@ -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', [
|
||||
|
||||
Reference in New Issue
Block a user