From d15f406059bdef8f941f8a90ed87b04afadb2d8b Mon Sep 17 00:00:00 2001 From: Anders Date: Tue, 4 Aug 2020 15:09:10 +0200 Subject: [PATCH] Fail message when making a reservation with taken machine and time --- .../Controllers/WashingReservationController.php | 12 +++++------- .../views/app/washing-reservations/create.blade.php | 1 + 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index 38d1d56..47954f1 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -67,15 +67,13 @@ class WashingReservationController extends Controller $machineReservation = new WashingReservation($data); $machineReservation->user_id = auth()->user()->id; - $machineReservation->save(); - $saved = $machineReservation->save(); + $allMachineReservations = WashingReservation::query()->where('time', '=', $request->time)->where('machine_id', '=', $request->machine_id)->get(); - if (!$saved) { - return Response::detect("washing-reservations.store", [ - "washing_reservation" => $machineReservation - ]); + if (count($allMachineReservations) > 0) { + return redirect()->route("washing-reservations.create", ["washing_reservation" => $machineReservation])->with('ReservationExists', '

Der findes allerede en reservation til denne tid, men denne vaskemaskine!

'); } else { + $machineReservation->save(); $reservations = WashingReservation::query()->paginate($request->input("limit", 20)); return redirect()->route('washing-reservations.appindex', ["reservations" => $reservations]); @@ -174,7 +172,7 @@ class WashingReservationController extends Controller foreach ($reservations as $reservation){ array_push($times, $reservation->time); } - //2020-07-28% + $output = json_encode(['date' => $date, 'washingmachines' => $machines, 'unavailable_times' => $times]); return Response($output); } diff --git a/skolehjem/resources/views/app/washing-reservations/create.blade.php b/skolehjem/resources/views/app/washing-reservations/create.blade.php index 25a48ad..ffe2275 100644 --- a/skolehjem/resources/views/app/washing-reservations/create.blade.php +++ b/skolehjem/resources/views/app/washing-reservations/create.blade.php @@ -7,6 +7,7 @@ @section("content")

Booking Liste

+ {!! session()->get('ReservationExists') !!}