diff --git a/app/Http/Controllers/Admin/NodesController.php b/app/Http/Controllers/Admin/NodesController.php index e0a7f0f46..0aa6aed19 100644 --- a/app/Http/Controllers/Admin/NodesController.php +++ b/app/Http/Controllers/Admin/NodesController.php @@ -186,4 +186,22 @@ class NodesController extends Controller } } + public function deleteNode(Request $request, $id) + { + $node = Models\Node::findOrFail($id); + $servers = Models\Server::where('node', $id)->count(); + if ($servers > 0) { + Alert::danger('You cannot delete a node with servers currently attached to it.')->flash(); + return redirect()->route('admin.nodes.view', [ + 'id' => $id, + 'tab' => 'tab_delete' + ]); + } + + $node->delete(); + Alert::success('Node successfully deleted.')->flash(); + return redirect()->route('admin.nodes'); + + } + } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index f84fdd826..e2ebef0cb 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -186,6 +186,11 @@ class AdminRoutes { 'uses' => 'Admin\NodesController@postAllocations' ]); + $router->delete('/view/{id}', [ + 'as' => 'admin.nodes.delete', + 'uses' => 'Admin\NodesController@deleteNode' + ]); + }); } diff --git a/resources/views/admin/nodes/view.blade.php b/resources/views/admin/nodes/view.blade.php index a6729b8de..13d5ff3fa 100644 --- a/resources/views/admin/nodes/view.blade.php +++ b/resources/views/admin/nodes/view.blade.php @@ -42,7 +42,7 @@