You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Laravel package that helps encrypt & decrypt certain defined table columns ensuring the data is secure in the database but can be accessed by the models.
1
+
# Laravel DB Encryptor
2
+
3
+
A Laravel package for secure, transparent encryption and decryption of sensitive model attributes, storing them in a dedicated table while keeping your main tables clean and fast.
4
+
5
+
## Features
6
+
- Seamless encryption/decryption of model attributes via a simple trait
7
+
- Encrypted data is stored in a separate `encrypted_attributes` table
8
+
- Only non-table attributes can be encrypted (enforced at runtime)
9
+
- Automatic loading and saving of encrypted attributes using Eloquent events
10
+
- No sensitive values are ever logged
11
+
- Easy integration: just add the trait and define `$encryptedProperties` in your model
12
+
- Compatible with Laravel 9+
13
+
14
+
## Requirements
15
+
- PHP 8.1+
16
+
- Laravel 9 or higher
17
+
- OpenSSL PHP extension
18
+
19
+
## How It Works
20
+
1. Add the `HasEncryptedAttributes` trait to your Eloquent model.
21
+
2. Define a public array property `$encryptedProperties` listing the attributes you want encrypted (these must NOT exist as columns in the model's table).
22
+
3. When you load a model, encrypted attributes are automatically decrypted and available as normal properties.
23
+
4. When you save a model, encrypted attributes are removed from the main table and securely stored in the `encrypted_attributes` table.
24
+
25
+
**Example Model:**
26
+
```php
27
+
use Wazza\DbEncrypt\Traits\HasEncryptedAttributes;
28
+
29
+
class User extends Model
30
+
{
31
+
use HasEncryptedAttributes;
32
+
33
+
protected $fillable = ['name', 'email'];
34
+
35
+
// Only non-table attributes can be encrypted!
36
+
public array $encryptedProperties = [
37
+
'social_security_number',
38
+
'private_note',
39
+
];
40
+
}
41
+
```
42
+
43
+
## Usage
44
+
- Use your model as normal:
45
+
```php
46
+
$user = User::find(1);
47
+
$user->social_security_number = '123-45-6789';
48
+
$user->private_note = 'Sensitive info';
49
+
$user->save();
50
+
51
+
// When you retrieve the user again, encrypted attributes are automatically decrypted:
0 commit comments