From 3dad3b57759143a8b67a02b4ac5642a874476139 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 21 Dec 2022 19:38:08 +0100 Subject: [PATCH] Catch position errors on bulk bookings --- app/Http/Controllers/BookingController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index 0610d132c..fbd9e6d07 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -226,7 +226,14 @@ public function storeBulk(Request $request) $booking->time_end = Carbon::createFromFormat('H:i', $data['end_at'])->setDateFrom($date); $booking->callsign = strtoupper($position); - $booking->position_id = Position::all()->firstWhere('callsign', strtoupper($position))->id; + + $positionModel = Position::all()->firstWhere('callsign', strtoupper($position)); + if(isset($positionModel)){ + $booking->position_id = Position::all()->firstWhere('callsign', strtoupper($position))->id; + } else { + return redirect(route('booking'))->withErrors('The position '.$position.' does not exist. The bulk booking stopped here, but previous positions in the list have been booked.')->withInput(); + } + $booking->name = $user->name; $booking->user_id = $user->id;