Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel committed Sep 12, 2020
2 parents 82e13f7 + 156e788 commit 46fda36
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Traits/EncryptableDbAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace betterapp\LaravelDbEncrypter\Traits;

use Exception;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Encryption\EncryptException;
use Illuminate\Support\Facades\Crypt;

/**
Expand All @@ -29,7 +30,7 @@ public function getAttributeValue($key)
}

// decrypt value before casts
if (in_array($key, $this->encryptable)) {
if (in_array($key, $this->encryptable) && !is_null($value) && $value !== '') {
$value = $this->decrypt($value);
}

Expand Down Expand Up @@ -130,7 +131,7 @@ private function encrypt($value)
{
try {
$value = Crypt::encrypt($value);
} catch (Exception $e) {}
} catch (EncryptException $e) {}

return $value;
}
Expand All @@ -144,7 +145,7 @@ private function decrypt($value)
{
try {
$value = Crypt::decrypt($value);
} catch (Exception $e) {}
} catch (DecryptException $e) {}

return $value;
}
Expand Down

0 comments on commit 46fda36

Please sign in to comment.