From 02b66840304c6533ed67b9838c2f443e46d8482e Mon Sep 17 00:00:00 2001 From: Anders Date: Wed, 5 Aug 2020 10:11:28 +0200 Subject: [PATCH] Added - Deleting Washing Reservations when deleting a washing machine --- skolehjem/app/Http/Controllers/WashingMachineController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/skolehjem/app/Http/Controllers/WashingMachineController.php b/skolehjem/app/Http/Controllers/WashingMachineController.php index 64eae55..07b1940 100644 --- a/skolehjem/app/Http/Controllers/WashingMachineController.php +++ b/skolehjem/app/Http/Controllers/WashingMachineController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\WashingReservation; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; use Illuminate\Http\Request; @@ -140,6 +141,10 @@ class WashingMachineController extends Controller public function destroy($id) { $machine = WashingMachine::find($id); + + $allReservations = WashingReservation::query()->where('machine_id', '=', $id); + + $allReservations->delete(); $machine->delete(); return redirect()->route("washing-machines.index");