User can add/edit flights

This commit is contained in:
2026-04-14 20:06:33 +10:00
parent a9aa65f0d2
commit 4110b52ba5
2 changed files with 52 additions and 46 deletions
+12 -19
View File
@@ -28,9 +28,9 @@ class FlightController extends Controller
'aircraft_id' => ['nullable', 'integer', 'exists:aircraft,id'],
'aircraft_registration' => ['nullable', 'string', 'max:10'],
'seat_number' => ['nullable', 'string', 'max:10'],
'seat_type_id' => ['nullable', 'integer', 'exists:seat_types,id'],
'flight_class_id' => ['nullable', 'integer', 'exists:flight_classes,id'],
'flight_reason_id' => ['nullable', 'integer', 'exists:flight_reasons,id'],
'seat_type_id' => ['integer', 'exists:seat_types,id'],
'flight_class_id' => ['integer', 'exists:flight_classes,id'],
'flight_reason_id' => ['integer', 'exists:flight_reasons,id'],
'note' => ['nullable', 'string', 'max:5000'],
'auto_update' => ['boolean'],
];
@@ -72,7 +72,6 @@ class FlightController extends Controller
private function flightPayload(array $validated): array
{
[$departureUtc, $arrivalUtc] = $this->convertedDates($validated);
return [
'departure_date' => $departureUtc,
'arrival_date' => $arrivalUtc,
@@ -115,9 +114,9 @@ class FlightController extends Controller
public function add(){
return Inertia::render('AddFlight', [
'seat_types' => SeatType::all()->map(fn ($s) => ['value' => $s->id, 'title' => $s->name]),
'flight_reasons' => FlightReason::all()->map(fn ($f) => ['value' => $f->id, 'title' => $f->name]),
'flight_classes' => FlightClass::all()->map(fn ($f) => ['value' => $f->id, 'title' => $f->name]),
'seat_types' => SeatType::all()->toArray(),
'flight_reasons' => FlightReason::all()->toArray(),
'flight_classes' => FlightClass::all()->toArray(),
]);
}
@@ -134,15 +133,9 @@ class FlightController extends Controller
'seat_number' => $flight->seat_number,
'note' => $flight->note,
'auto_update' => $flight->auto_update,
'seat_type' => $flight->seatType
? ['value' => $flight->seatType->id, 'title' => $flight->seatType->name]
: null,
'flight_class' => $flight->flightClass
? ['value' => $flight->flightClass->id, 'title' => $flight->flightClass->name]
: null,
'flight_reason' => $flight->flightReason
? ['value' => $flight->flightReason->id, 'title' => $flight->flightReason->name]
: null,
'seat_type' => $flight->seatType->toArray(),
'flight_class' => $flight->flightClass->toArray(),
'flight_reason' => $flight->flightReason->toArray(),
'airline_options' => $flight->airline
? [['value' => $flight->airline->id, 'title' => $flight->airline->name]]
: [],
@@ -154,9 +147,9 @@ class FlightController extends Controller
];
return Inertia::render('AddFlight', [
'flight' => $flightData,
'seat_types' => SeatType::all()->map(fn($t) => ['value' => $t->id, 'title' => $t->name]),
'flight_classes' => FlightClass::all()->map(fn($t) => ['value' => $t->id, 'title' => $t->name]),
'flight_reasons' => FlightReason::all()->map(fn($t) => ['value' => $t->id, 'title' => $t->name]),
'seat_types' => SeatType::all()->toArray(),
'flight_classes' => FlightClass::all()->toArray(),
'flight_reasons' => FlightReason::all()->toArray(),
]);
}
}