laravel-aescrypt
laravel-aescrypt copied to clipboard
Nothing happended
Hi,
thank you for this plugin. I have a problem with saving encrypted data. Then i save my model, the normal unencrypted data saved to the database. What´s my mistake? I declare the encryption key in the env-file like you describe it in your introduction.
Thank you for help
Same issue here on a new Laravel project (5.7.19). It does work when you update your model with a new value.
This seems to be caused by the different handling in the performInsert and performUpdate functions in Illuminate\Database\Eloquent\Model.
The performInsert function uses Model->getAttributes(), which returns the unencrypted values. The performUpdate function uses Model->getDirty(), which returns the encrypted values.
Example:
$ php artisan tinker
Psy Shell v0.9.9 (PHP 7.3.0 — cli) by Justin Hileman
>>> $account=new App\testaccount();
=> App\testaccount {#3005}
>>> $account->username='user1'
=> "user1"
>>> $account->password1='test'
=> "test"
>>> $account->getAttributes();
=> [
"username" => "user1",
"password1" => "test",
]
>>> $account->getDirty();
=> [
"username" => "user1",
"password1" => "__AESCRYPT__:lkoFwYJFVGm3CLjhuKxVqQ==",
]
>>>
Currently i've removed the (overridden) function getAttributes() from Aescrypt.php, but i don't know if this has any impact on other things.