'integer', 'public_key' => 'encrypted', ]; public function user(): BelongsTo { return $this->belongsTo(User::class); } public function servers(): BelongsToMany { return $this->belongsToMany(Server::class, 'server_ssh_keys') ->withPivot('status') ->withTimestamps(); } public function existsOnServer(Server $server): bool { return (bool) $this->servers()->where('id', $server->id)->first(); } public function deployTo(Server $server): void { $server->sshKeys()->attach($this, [ 'status' => SshKeyStatus::ADDING, ]); dispatch(new DeploySshKeyToServer($server, $this))->onConnection('ssh'); } public function deleteFrom(Server $server): void { $this->servers()->updateExistingPivot($server->id, [ 'status' => SshKeyStatus::DELETING, ]); dispatch(new DeleteSshKeyFromServer($server, $this))->onConnection('ssh'); } }