PHP code example of phpcodersnp / laravel-database-encryption

1. Go to this page and download the library: Download phpcodersnp/laravel-database-encryption library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpcodersnp / laravel-database-encryption example snippets


whereEncrypted('first_name','john')
orWhereEncrypted('last_name','!=','Doe')

orderByEncrypted('last_name','asc')
orderByEncrypted('last_name','desc')

selectEncrypted([
    "first_name as userFirstName",
    "last_name",
    ]) // array only

concatEncrypted('first_name , " " ,last_name AS fullUserName')

'providers' => [
    ...
    \PHPCodersNp\DBEncryption\Providers\DBEncryptionServiceProvider::class,
],

$app->configure('laravelDatabaseEncryption');

$app->register(PHPCodersNp\DBEncryption\Providers\DBEncryptionServiceProvider::class);


use PHPCodersNp\DBEncryption\Traits\EncryptedAttribute;

class User extends Eloquent {
    use EncryptedAttribute;

    /**
        * The attributes that should be encrypted on save.
        *
        * @var array
        */
    protected $encryptable = [
        'first_name', 'last_name', 'email'
    ];
}
     
$validator = validator(['email'=>'[email protected]'], ['email'=>'exists_encrypted:users,email']);
$validator = validator(['email'=>'[email protected]'], ['email'=>'unique_encrypted:users,email']);

User::whereEncrypted('email','[email protected]')
        ->orWhereEncrypted('email','[email protected]')
        ->first();
bash
php artisan vendor:publish --provider="PHPCodersNp\DBEncryption\Providers\DBEncryptionServiceProvider"
bash
cp vendor/phpcodersnp/laravel-database-encryption/src/Config/config.php config/laravelDatabaseEncryption.php
bash
php artisan encryptable:encryptModel 'App\Models\User'
bash
php artisan encryptable:decryptModel 'App\Models\User'