glorand/laravel-model-settings

Encrypt Setting data

Closed this issue · 2 comments

Would it be possible to quickly add in the ability to encrypt at the item level for model storage?

Basically, when performing an update ->update('item', $item_value, true) add a third Boolean option that will auto encrypt the data for storage and then upon retrieval decrypt it?

I think that encryption and decryption of data is not the role of this package.
If you want to save setting values encrypted than on read decrypt you can use core laravel facade or helper functions.

$model->settings()->update('item', encrypt('item_value')),

You could do this by using accessors and mutators. For example, on your model you could have:

    /**
     * @param $settings
     */
    public function setSettingsAttribute($settings)
    {
        $this->attributes[$this->getSettingsFieldName()] = encrypt($settings);
    }

    /**
     * @param $value
     * @return mixed
     */
    public function getSettingsAttribute($value)
    {
        return decrypt($value);
    }

This would encrypt the full settings field and not individual settings, however.