laravel-db-encrypter

repository·master·Indexed 18 days ago

https://github.com/betterapp/laravel-db-encrypter

A Laravel package that automatically encrypts and decrypts Eloquent model attributes using the standard Laravel Crypt service via the EncryptableDbAttribute trait.

Tokens
567
Snippets
2
Records
3
Agent score
13%

What's inside laravel-db-encrypter

  1. Configure database schema for encrypted attributes

    master

    Encrypted values are stored as plain text and typically consume more space than unencrypted values.

    Recommendations:

    • Alter your table columns to the TEXT type to ensure enough space for the encrypted string.
    • If using VARCHAR or CHAR, verify that the column length is sufficient to hold the encrypted output.

    Note on existing data: If you add attributes to the $encryptable array in an existing model, unencrypted data currently in the database will be returned as-is. Once you save those values, they will be encrypted and function normally.

  2. Encrypt Eloquent model attributes

    master

    To encrypt and decrypt model attributes, follow these steps:

    1. Import and use the betterapp\LaravelDbEncrypter\Traits\EncryptableDbAttribute trait within your Eloquent model.
    2. Define a protected $encryptable array containing the names of the attributes you want to encrypt.

    You can still use Laravel's native $casts property to cast the decrypted values (e.g., to datetime or integer) after they have been decrypted by the trait.

    use betterapp\LaravelDbEncrypter\Traits\EncryptableDbAttribute;
    
    class Client extends Eloquent {
        use EncryptableDbAttribute;
       
        /** @var array The attributes that should be encrypted/decrypted */
        protected $encryptable = [
            'id_number', 
            'email',
        ];
    }
  3. Install laravel-db-encrypter via Composer

    master

    Install the package using Composer. Choose the version compatible with your Laravel installation:

    Laravel VersionCommand
    12composer require betterapp/laravel-db-encrypter:^v5
    11composer require betterapp/laravel-db-encrypter:^v4
    10composer require betterapp/laravel-db-encrypter:^v3
    9composer require betterapp/laravel-db-encrypter:^v2
    6, 7, 8composer require betterapp/laravel-db-encrypter:^v1
    $ composer require betterapp/laravel-db-encrypter