diff --git a/skolehjem/app/Http/Controllers/LocationController.php b/skolehjem/app/Http/Controllers/LocationController.php index d60aba5..33b73f5 100644 --- a/skolehjem/app/Http/Controllers/LocationController.php +++ b/skolehjem/app/Http/Controllers/LocationController.php @@ -165,82 +165,4 @@ class LocationController extends Controller return 1; } } - - - - - public function search(Request $request){ - if($request->ajax()){ - $output = "". - "Navn". - "Lokation". - "\"Update\"". - "\"Delete\"". - ""; - - 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"). - - ''. - '
'. - ''. - ''; - } - }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/app/Http/Controllers/WashingMachineController.php b/skolehjem/app/Http/Controllers/WashingMachineController.php index 921e5bb..85b458d 100644 --- a/skolehjem/app/Http/Controllers/WashingMachineController.php +++ b/skolehjem/app/Http/Controllers/WashingMachineController.php @@ -10,6 +10,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; use App\WashingMachine; +use Illuminate\Support\Facades\DB; use Illuminate\View\View; class WashingMachineController extends Controller @@ -167,4 +168,78 @@ class WashingMachineController extends Controller return 1; } } + + public function search(Request $request){ + if($request->ajax()){ + $output = "". + "Navn". + "Lokation". + "\"Update\"". + "\"Delete\"". + ""; + + if($request->option !== 'all') { + $machines = 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, washing_machines.id as id')) + ->where('locations.id', '=', $request->option) + ->get(); + + if(count($machines) !== 0){ + foreach ($machines as $machine){ + $output.=''. + '' . $machine->washing_name . ''. + '' . $machine->location_name . ''. + ' $machine->id ]) . '">Update'. + '
$machine->id ]). '" class="w-100 nostyle">'. + csrf_field(). + method_field("delete"). + + ''. + '
'. + ''. + ''; + } + }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 8e1844b..9be1d94 100644 --- a/skolehjem/resources/views/admin/washing-machines/index.blade.php +++ b/skolehjem/resources/views/admin/washing-machines/index.blade.php @@ -49,7 +49,7 @@ console.log($value); $.ajax({ type: 'get', - url: '{{route('locations.search')}}', + url: '{{route('washing-machines.search')}}', data: {'option':$value}, success:function (data) { console.log($value); diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index d03be30..9690eb4 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -49,7 +49,7 @@ Route::get("/rolesapi", "RolesController@search")->name("roles.search"); Route::get("/userapi", "UserController@search")->name("users.search"); Route::get("/vaskeapi", "WashingReservationController@search")->name("washing-reservations.search"); Route::get("/risrosapi", "FeedbackController@search")->name("feedbacks.search"); -Route::get("/locationapi", "LocationController@search")->name("locations.search"); +Route::get("/machineapi", "WashingMachineController@search")->name("washing-machines.search"); //Cookies Route::get("/languages", "UserController@setLanguages")->name("users.setLanguages");