protected function performInsert(Builder $query)
    {
        $encryptedFields = static::getEncryptedFields();
        if (count($encryptedFields) && !$this->getEncryptKey()) {
            throw new \RuntimeException("No encryption key specified");
        }
        $originalAttributes = $this->attributes;
        foreach ($encryptedFields as $encryptedField) {
            if (isset($this->attributes[$encryptedField])) {
                $this->attributes[$encryptedField] = DB::raw(static::getEncryptionService()->getEncryptExpression($this->attributes[$encryptedField], static::getEncryptKey()));
            }
        }
        $inserted = parent::performInsert($query);

        // reset the attributes to the decrypted values
        foreach ($encryptedFields as $encryptedField) {
            if (isset($this->attributes[$encryptedField])) {
                $this->attributes[$encryptedField] = $originalAttributes[$encryptedField];
            }
        }
        return $inserted;
    }