PHP code example of jfelixstudio / laravel-mysql-encrypt
1. Go to this page and download the library: Download jfelixstudio/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/ */
jfelixstudio / laravel-mysql-encrypt example snippets
namespace App;
use JfelixStudio\MysqlEncrypt\Traits\Encryptable;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use Encryptable; // <-- 1. Include trait
protected $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->rememberToken();
$table->timestamps();
});
// Once the table has been created, use ALTER TABLE to create VARBINARY
// or BLOB types to store encrypted data.
DB::statement('ALTER TABLE `users` ADD `first_name` VARBINARY(300)');
DB::statement('ALTER TABLE `users` ADD `last_name` VARBINARY(300)');
DB::statement('ALTER TABLE `users` ADD `email` VARBINARY(300)');
DB::statement('ALTER TABLE `users` ADD `telephone` VARBINARY(50)');