get(); foreach ($vpns as $vpn) { $internalPeers = Peer::query()->where("vpn_id", "=", $vpn->id)->get(); $this->info("Import for ".$vpn->name); $knownpeers=[]; foreach ($internalPeers as $p) { $knownpeers[] = $p->public_key; } $peers = $wgrest->getPeers($vpn->name); foreach ($peers as $peer) { if(!in_array($peer["public_key"], $knownpeers)) { $this->info("Import ".$peer["public_key"]); $peerToSave = new Peer(); $peerToSave->name = "import"; $peerToSave->public_key = $peer["public_key"]; $peerToSave->allowed_ips = implode(",", $peer["allowed_ips"]); if(isset($peer["preshared_key"])) { $peerToSave->preshared_key = $peer["preshared_key"]; } if(count($peer["allowed_ips"]) == 1) { $n = Network::parse($peer["allowed_ips"][0]); if((string)$n->getNetmask()=="255.255.255.255") { $peerToSave->ip = (string)$n->getIP(); $peerToSave->allowed_ips = null; } } $peerToSave->imported = true; $peerToSave->vpn_id = $vpn->id; $peerToSave->saveOrFail(); } } } } }