|
5 | 5 | use Wazza\DbEncrypt\Http\Controllers\DbEncryptController; |
6 | 6 | use Wazza\DbEncrypt\Models\EncryptedAttributes; |
7 | 7 | use Wazza\DbEncrypt\Helper\Encryptor; |
| 8 | +use Illuminate\Support\Facades\Log; |
8 | 9 |
|
9 | 10 | /** |
10 | 11 | * Include this trait in your model to enable database encryption functionality. |
@@ -57,7 +58,11 @@ public function loadEncryptedAttributes(): void |
57 | 58 | $dnEncryptController->setModel($this); |
58 | 59 | $dnEncryptController->decrypt(); |
59 | 60 | } catch (\Throwable $e) { |
60 | | - // Optionally log or handle decryption errors |
| 61 | + // Log the error with context, but never log sensitive values |
| 62 | + Log::error('DB Encrypt: Failed to decrypt attributes for model ' . get_class($this) . ' (ID: ' . ($this->getKey() ?? 'n/a') . '): ' . $e->getMessage()); |
| 63 | + |
| 64 | + // Optionally, throw a custom exception for the application layer |
| 65 | + throw new \RuntimeException('Failed to decrypt encrypted attributes for this model. Please check the logs for details.', 0, $e); |
61 | 66 | } |
62 | 67 | } |
63 | 68 |
|
@@ -102,7 +107,11 @@ public function saveEncryptedAttributes(): void |
102 | 107 | $dnEncryptController->encryptProperty($prop); |
103 | 108 | } |
104 | 109 | } catch (\Throwable $e) { |
105 | | - // Optionally log or handle encryption errors |
| 110 | + // Log the error with context, but never log sensitive values |
| 111 | + Log::error('DB Encrypt: Failed to decrypt attributes for model ' . get_class($this) . ' (ID: ' . ($this->getKey() ?? 'n/a') . '): ' . $e->getMessage()); |
| 112 | + |
| 113 | + // Optionally, throw a custom exception for the application layer |
| 114 | + throw new \RuntimeException('Failed to decrypt encrypted attributes for this model. Please check the logs for details.', 0, $e); |
106 | 115 | } |
107 | 116 |
|
108 | 117 | $this->_encryptedAttributesBuffer = []; |
|
0 commit comments