Skip to content

Commit 46fda36

Browse files
author
daniel
committed
Merge remote-tracking branch 'origin/master'
2 parents 82e13f7 + 156e788 commit 46fda36

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Traits/EncryptableDbAttribute.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace betterapp\LaravelDbEncrypter\Traits;
44

5-
use Exception;
5+
use Illuminate\Contracts\Encryption\DecryptException;
6+
use Illuminate\Contracts\Encryption\EncryptException;
67
use Illuminate\Support\Facades\Crypt;
78

89
/**
@@ -29,7 +30,7 @@ public function getAttributeValue($key)
2930
}
3031

3132
// decrypt value before casts
32-
if (in_array($key, $this->encryptable)) {
33+
if (in_array($key, $this->encryptable) && !is_null($value) && $value !== '') {
3334
$value = $this->decrypt($value);
3435
}
3536

@@ -130,7 +131,7 @@ private function encrypt($value)
130131
{
131132
try {
132133
$value = Crypt::encrypt($value);
133-
} catch (Exception $e) {}
134+
} catch (EncryptException $e) {}
134135

135136
return $value;
136137
}
@@ -144,7 +145,7 @@ private function decrypt($value)
144145
{
145146
try {
146147
$value = Crypt::decrypt($value);
147-
} catch (Exception $e) {}
148+
} catch (DecryptException $e) {}
148149

149150
return $value;
150151
}

0 commit comments

Comments
 (0)