PHP code example of wazza / laravel-db-encryption

1. Go to this page and download the library: Download wazza/laravel-db-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/ */

    

wazza / laravel-db-encryption example snippets


use Wazza\DbEncrypt\Traits\HasEncryptedAttributes;

class User extends Model
{
    use HasEncryptedAttributes;

    protected $fillable = ['name', 'email'];

    // Only non-table attributes can be encrypted!
    public array $encryptedProperties = [
        'social_security_number',
        'private_note',
    ];
}

$user = User::find(1);
$user->social_security_number = '123-45-6789';
$user->private_note = 'Sensitive info';
$user->save();

// When you retrieve the user again, encrypted attributes are automatically decrypted:
$user = User::find(1);
echo $user->social_security_number; // '123-45-6789'

// Find users with a specific social security number
$users = User::whereEncrypted('social_security_number', '123-45-6789')->get();
sh
   php artisan vendor:publish --provider="Wazza\DbEncrypt\DbEncryptServiceProvider"
   
sh
   php artisan migrate