v0.10.5 - Fixed vagttelefon

Added: Washing Machines & their reservations now delete when the location gets removed
This commit is contained in:
Anders
2020-08-18 12:25:32 +02:00
parent d49a896fc0
commit ddbc3b8b60
2 changed files with 20 additions and 7 deletions
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Location;
use App\WashingMachine;
use App\WashingReservation;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@@ -130,12 +131,21 @@ class LocationController extends Controller
*/
public function destroy($id)
{
$locations = Location::find($id);
$location = Location::find($id);
$washingMachines = WashingMachine::query()->where('location_id', '=', $id)->get();
$washingMachines = WashingMachine::query()->where('location_id', '=', $id);
$washingMachines->delete();
foreach ($washingMachines as $machine) {
$washingReservations = WashingReservation::query()->where('machine_id', '=', $machine->id)->get();
$locations->delete();
foreach ($washingReservations as $reservation)
{
$reservation->delete();
}
$machine->delete();
}
$location->delete();
return redirect()->route("locations.index");
}