Skip to content

Commit

Permalink
Catch position errors on bulk bookings
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Dec 21, 2022
1 parent 2af0168 commit 3dad3b5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/Http/Controllers/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3dad3b5

Please sign in to comment.