Skip to content

Commit 0040822

Browse files
committed
fallback for failed decryption
1 parent 2222e6c commit 0040822

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/HasEncryptedAttributes.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Buildcode\LaravelDatabaseEmails;
44

5+
use Illuminate\Contracts\Encryption\DecryptException;
6+
57
trait HasEncryptedAttributes
68
{
79
/**
@@ -41,7 +43,11 @@ public function getAttribute($key)
4143
$value = $this->attributes[$key];
4244

4345
if ($this->isEncrypted() && in_array($key, $this->encrypted)) {
44-
$value = decrypt($value);
46+
try {
47+
$value = decrypt($value);
48+
} catch (DecryptException $e) {
49+
$value = '';
50+
}
4551
}
4652

4753
if (in_array($key, $this->encoded) && is_string($value)) {

0 commit comments

Comments
 (0)