PHP code example of tapanderasari / laravel-mysql-encrypt

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

    

tapanderasari / laravel-mysql-encrypt example snippets




namespace App;

use TapanDerasari\MysqlEncrypt\Traits\Encryptable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Encryptable; // <-- 1. Include trait

    public array $encryptable = [ // <-- 2. Include columns to be encrypted
        'email',
        'first_name',
        'last_name',
        'telephone',
    ];
}

Schema::create('users', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('password');
    $table->binary('first_name', 300);  // VARBINARY(300)
    $table->binary('last_name', 300);
    $table->binary('email', 300);
    $table->binary('telephone', 50);
    $table->rememberToken();
    $table->timestamps();
});

User::whereEncrypted('email', '[email protected]')->first();
User::whereNotEncrypted('email', '[email protected]')->get();

User::whereEncrypted('email', '[email protected]')
    ->orWhereEncrypted('email', '[email protected]')
    ->get();

User::whereNotEncrypted('email', '[email protected]')
    ->orWhereNotEncrypted('email', '[email protected]')
    ->get();

User::whereEncryptedLike('first_name', 'John')->get();
User::orWhereEncryptedLike('first_name', 'Jane')->get();

User::orderByEncrypted('first_name', 'asc')->get();
User::orderByEncryptedSort('last_name', 'desc')->get();
bash
php artisan vendor:publish --provider="TapanDerasari\MysqlEncrypt\Providers\LaravelServiceProvider"

php artisan make:command EncryptionForExistingData