PHP code example of elgibor-solution / laravel-database-encryption

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

    

elgibor-solution / laravel-database-encryption example snippets


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

    
    use ESolution\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'
        ];
    }

    namespace App\Http\Controllers;

    use App\User;
    class UsersController extends Controller {
        public function index(Request $request)
        {
            $user = User::whereEncrypted('first_name','john')
                        ->orWhereEncrypted('last_name','!=','Doe')->firstOrFail();
            
            return $user;
        }
    }
 
php artisan encryptable:encryptModel 'App\User'
 
php artisan encryptable:decryptModel 'App\User'
      
      $validator = validator(['email'=>'[email protected]'], ['email'=>'exists_encrypted:users,email']);
      $validator = validator(['email'=>'[email protected]'], ['email'=>'unique_encrypted:users,email']);