From 522cf9cdf76439b4b0e8ebae4e81a6d782ebb2a3 Mon Sep 17 00:00:00 2001 From: Neerholt Date: Fri, 21 Aug 2020 10:54:00 +0200 Subject: [PATCH 1/4] v0.10.12a - Made filter for washing machines done --- .../Http/Controllers/LocationController.php | 84 +++++++++++++------ .../admin/washing-machines/index.blade.php | 5 +- 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/skolehjem/app/Http/Controllers/LocationController.php b/skolehjem/app/Http/Controllers/LocationController.php index 29d7c92..94fa600 100644 --- a/skolehjem/app/Http/Controllers/LocationController.php +++ b/skolehjem/app/Http/Controllers/LocationController.php @@ -7,6 +7,8 @@ use App\WashingMachine; use App\WashingReservation; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Facades\DB; +use function GuzzleHttp\Promise\all; class LocationController extends Controller { @@ -176,39 +178,67 @@ class LocationController extends Controller "\"Delete\"". ""; - if($request) { - $locations = Location::query()->orderBy('created_at', 'desc')->where('name', '=', $request->option)->get(); - //$machines = WashingMachine::query()->where('created_at', '=', $locations->created_at)->get(); - } - elseif($request->option == "all"){ - $locations = Location::all(); - } + if($request->option !== 'all') { + $locations = DB::table('washing_machines') + ->join('locations', 'washing_machines.location_id','=', 'locations.id') + ->select(DB::raw('washing_machines.name as washing_name, locations.name as location_name, locations.id as id')) + ->where('locations.id', '=', $request->option) + ->get(); + if(count($locations) !== 0){ + foreach ($locations as $key => $location){ + $output.=''. + '' . $location->washing_name . ''. + '' . $location->location_name . ''. + '
$location->id ]). '" class="w-100 nostyle">'. + ' $location->id ]). '" class="w-100 nostyle">'. + csrf_field(). + method_field("delete"). - if(count($locations) !== 0){ - foreach ($locations as $key => $location){ + ''. + '
'. + ''. + ''; + } + }else{ $output.=''. - //'' . $location->name . ''. - '

Test data

'. - '' . $location->name . ''. - '
$location ]). '" class="w-100 nostyle">'. - ' $location ]). '" class="w-100 nostyle">'. - csrf_field(). - method_field("delete"). - - ''. - '
'. - ''. + 'Det er ikke blivet oprettet nogen vaskmaskine på denne lokation i nu'. + ''. + ''. + ''. ''; } - }else{ - $output.=''. - 'Det er ikke blivet oprettet nogen vaskmaskine på denne lokation i nu'. - ''. - ''. - ''. - ''; } + elseif($request->option === "all"){ + $machines = WashingMachine::all(); + + if(count($machines) !== 0){ + foreach($machines as $machine) { + $output.= ''. + ''.$machine->name.''. + ''.Location::query()->where("id", "=", $machine->location_id)->first()->name.''. + ' $machine->id]) . '">Update'. + '
'. + csrf_field(). + method_field("delete"). + ''. + '
'. + ''. + ''; + } + }else{ + $output.=''. + 'Det er ikke blivet oprettet nogen vaskmaskine på denne lokation i nu'. + ''. + ''. + ''. + ''; + } + } + + + + return Response($output); } } diff --git a/skolehjem/resources/views/admin/washing-machines/index.blade.php b/skolehjem/resources/views/admin/washing-machines/index.blade.php index d4e3e41..8e1844b 100644 --- a/skolehjem/resources/views/admin/washing-machines/index.blade.php +++ b/skolehjem/resources/views/admin/washing-machines/index.blade.php @@ -16,7 +16,7 @@ @@ -46,12 +46,13 @@