Add more airlines and fix edit bugs

This commit is contained in:
2026-04-20 16:42:11 +10:00
parent 061ee9dd07
commit e007824fa9
15 changed files with 458 additions and 276 deletions
+9 -9
View File
@@ -97,9 +97,9 @@ class FlightController extends Controller
{
$validated = $request->validate($this->rules());
auth()->user()->flights()->create($this->flightPayload($validated));
$newFlight = auth()->user()->flights()->create($this->flightPayload($validated));
return redirect()->route('dashboard', Auth::user()->name);
return redirect()->route('profile.departure-board', [Auth::user()->name, $newFlight->id]);
}
public function update(Request $request, UserFlight $flight)
@@ -110,14 +110,14 @@ class FlightController extends Controller
$flight->update($this->flightPayload($validated));
return redirect()->route('dashboard', Auth::user()->name);
return redirect()->route('profile.departure-board', [Auth::user()->name, $flight->id]);
}
public function add(){
return Inertia::render('AddFlight', [
'seat_types' => SeatType::all()->toArray(),
'flight_reasons' => FlightReason::all()->toArray(),
'flight_classes' => FlightClass::all()->toArray(),
'seat_types' => SeatType::orderBy('id')->get()->toArray(),
'flight_reasons' => FlightReason::orderBy('id')->get()->toArray(),
'flight_classes' => FlightClass::orderBy('id')->get()->toArray(),
]);
}
@@ -148,9 +148,9 @@ class FlightController extends Controller
];
return Inertia::render('AddFlight', [
'flight' => $flightData,
'seat_types' => SeatType::all()->toArray(),
'flight_classes' => FlightClass::all()->toArray(),
'flight_reasons' => FlightReason::all()->toArray(),
'seat_types' => SeatType::orderBy('id')->get()->toArray(),
'flight_reasons' => FlightReason::orderBy('id')->get()->toArray(),
'flight_classes' => FlightClass::orderBy('id')->get()->toArray(),
]);
}
}
@@ -10,7 +10,7 @@ use Inertia\Inertia;
class FlightProfileController extends Controller
{
public function profileData(string $username, string $view) : array {
public function profileData(string $username, string $view, ?int $selectedFlightId = null) : array {
$user = User::whereRaw(DB::raw('LOWER(name) = ?'), [strtolower($username)])->firstOrFail();
$flights = UserFlight::where('user_id', $user->id)
@@ -33,11 +33,12 @@ class FlightProfileController extends Controller
'canEdit' => auth()->check() && auth()->id() === $user->id,
'flights' => UserFlightResource::collection($flights)->resolve(),
'initialView' => $view,
'selectedFlightId' => $selectedFlightId,
];
}
public function departureBoard(string $username){
$profileData = $this->profileData($username, 'board');
public function departureBoard(string $username, ?UserFlight $flight = null){
$profileData = $this->profileData($username, 'board', $flight?->id);
return Inertia::render('UserProfile', $profileData);
}