listDevices(); foreach($res as $network) { $setAdmins = false; $this->info("Update Device: ".$network["name"]); $vpn = VPN::query()->where("name", "=", $network["name"])->first(); if(is_null($vpn)) { $this->info("Create New Device: ".$network["name"]); $vpn = new VPN(); $vpn->displayName = $network["name"]; $setAdmins = true; } $vpn->name = $network["name"]; $vpn->listen_port = $network["listen_port"]; $vpn->network = $network["network"]; $vpn->private_key = $network["private_key"]; $vpn->public_key = $network["public_key"]; $vpn->saveOrFail(); if($setAdmins) { $admins = User::findAdmins(); foreach($admins as $admin) { $access = new VPNAccess(); $access->user_id = $admin->id; $access->vpn_id = $vpn->id; $access->status = "Admin"; $access->saveOrFail(); } } } return 0; } }