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
"
 | ".
"";
- 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 . ' | '.
+ ' |
';
+ }
+ }else{
$output.=''.
- //'' . $location->name . ' | '.
- 'Test data | '.
- '' . $location->name . ' | '.
- ' |
';
}
- }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]) . '"> . ') | '.
+ ''.
+ 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 @@