diff --git a/skolehjem/app/Http/Controllers/WashingMachineController.php b/skolehjem/app/Http/Controllers/WashingMachineController.php index c13d537..07b5eeb 100644 --- a/skolehjem/app/Http/Controllers/WashingMachineController.php +++ b/skolehjem/app/Http/Controllers/WashingMachineController.php @@ -59,9 +59,14 @@ class WashingMachineController extends Controller ]); $machine = new WashingMachine($data); - $machine->save(); + $saved = $machine->save(); - return Response::detect("washing-machines.store"); + if(!$saved){ + return Response::detect("washing-machines.store"); + }else{ + $machines = WashingMachine::query()->paginate($request->input("limit", 20)); + return Response::detect("washing-machines.index", ['machines' => $machines]); + } } /** @@ -117,7 +122,7 @@ class WashingMachineController extends Controller return Response::detect("washing-machines.update", [ "machine" => $machine ]); - }else{ + } else { $machines = WashingMachine::query()->paginate($request->input("limit", 20)); return Response::detect("washing-machines.index", [ "machines" => $machines diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index 7b691cd..a028c66 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -65,7 +65,16 @@ class WashingReservationController extends Controller $machineReservation = new WashingReservation($data); $machineReservation->save(); - return Response::detect("washing-reservations.store"); + $saved = $machineReservation->save(); + + if(!$saved){ + return Response::detect("washing-reservations.store", [ + "washing_reservation" => $machineReservation + ]); + }else{ + $reservations = WashingReservation::query()->paginate($request->input("limit", 20)); + return Response::detect("washing-machines.index", ['reservations' => $reservations]); + } } /** @@ -115,11 +124,16 @@ class WashingReservationController extends Controller $machineReservation->update($data); - $machineReservation->save(); + $saved = $machineReservation->save(); - return Response::detect("washing-reservations.update", [ - "washing_reservation" => $machineReservation - ]); + if(!$saved){ + return Response::detect("washing-reservations.update", [ + "washing_reservation" => $machineReservation + ]); + }else{ + $reservations = WashingReservation::query()->paginate($request->input("limit", 20)); + return Response::detect("washing-machines.index", ['reservations' => $reservations]); + } } /**