PHP code example of thomascombe / encryptable-fields
1. Go to this page and download the library: Download thomascombe/encryptable-fields 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/ */
thomascombe / encryptable-fields example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Webqamdev\EncryptableFields\Models\Traits\EncryptableFields;
class User extends Model
{
use EncryptableFields;
const COLUMN_LASTNAME = 'lastname';
const COLUMN_LASTNAME_HASH = 'lastname_hash';
const COLUMN_FIRSTNAME = 'firstname';
const COLUMN_FIRSTNAME_HASH = 'firstname_hash';
const COLUMN_EMAIL = 'mail';
/**
* The attributes that should be encrypted in database.
*
* @var string[]
*/
protected $encryptable = [
self::COLUMN_FIRSTNAME => self::COLUMN_FIRSTNAME_HASH,
self::COLUMN_LASTNAME => self::COLUMN_LASTNAME_HASH,
self::COLUMN_EMAIL,
];
use Webqamdev\EncryptableFields\Rules\Exists\Hashed;
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'email' => [
new Hashed(User::class, 'email'),
// or new Hashed('users', 'email'),
],
];
}
use Webqamdev\EncryptableFields\Rules\Unique\Hashed;
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'email' => [
new Hashed(User::class, 'email'),
// or new Hashed('users', 'email'),
],
];
}
use Webqamdev\EncryptableFields\Rules\Exists\Encrypted;
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'email' => [
new Encrypted(User::class, 'email'),
// or new Encrypted('users', 'email'),
],
];
}
use Webqamdev\EncryptableFields\Rules\Unique\Encrypted;
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'email' => [
new Encrypted(User::class, 'email'),
// or new Encrypted('users', 'email'),
],
];
}